Merge two different structs, and overwrite fields
To make creating struct for tests easier.
to := testStruct{
String: "default string",
Bool: true,
Integer: 100,
Float: float64(1.001112),
Time: time.Now(),
LargeNum: testSubStruct{
IntPart: 1000,
IsZero: false,
},
Decimal: decimal.NewFromFloat(1000),
}
from := otherStruct{
String: "another string",
}
var target testStruct
if err := MergeOverwrite(to, from, &target); err != nil {
t.Fatal(err)
}
Merge receives two POINTER of structs, and merges them excluding fields with tag name:
structs, value "-"
Merge(dst, src interface{})
Merge 2 structs overwriten
MergeOverwrite(to, from, dst interface{})
Merge 2 structs overwriten supported cammel case
MergeOverwriteCamel(to, from, dst interface{})
Merge 2 structs to map
MergeToMap(to, from interface{}) (map[string]interface{}, error)
Convert string json to map
ConvertStringToMap(in string) map[string]interface{}
Request handler requires Go v1.11+ to run.
Install the package.
$ go get github.com/onskycloud/structsSee KUBERNETES.md
- Write MORE Tests
- Add Night Mode
MIT