add interface supported

This commit is contained in:
fancl 2023-09-12 16:50:45 +08:00
parent 9cfa81115f
commit 2db8293160
2 changed files with 21 additions and 17 deletions

View File

@ -114,6 +114,8 @@ func safeAssignment(variable reflect.Value, value interface{}) (err error) {
default:
variable.SetString(fmt.Sprint(value))
}
case reflect.Interface:
variable.Set(rv)
default:
err = fmt.Errorf("unsupported kind %s", kind)
}

View File

@ -28,26 +28,28 @@ type fake struct {
func TestSetter(t *testing.T) {
dst := &fake{}
ms := map[string]any{
"name": "aa",
"age": "5",
"usage": []map[string]any{
{
"in": 15,
"bs": map[string]any{
"aa": "vv",
},
vs := map[string]any{
"name": "xxx",
}
vvs := []map[string]any{
{
"in": 15,
"bs": map[string]any{
"aa": "vv",
},
},
"xx": map[string]any{"in": 45},
"ax": map[string]any{"in": 55},
"ss": []string{"11", "ss"},
"ds": []int{55, 55, 34},
"ms": map[string]any{"aa": "23"},
}
ms := map[string]any{
"name": "aa",
"age": "5",
"usage": vvs,
"xx": map[string]any{"in": 45},
"ax": map[string]any{"in": 55},
"ss": []string{"11", "ss"},
"ds": []int{55, 55, 34},
"ms": map[string]any{"aa": "23"},
"ab": map[string]any{
"xx": map[string]any{
"name": "xxx",
},
"xx": vs,
},
}
err := Setter(dst, ms)