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: default:
variable.SetString(fmt.Sprint(value)) variable.SetString(fmt.Sprint(value))
} }
case reflect.Interface:
variable.Set(rv)
default: default:
err = fmt.Errorf("unsupported kind %s", kind) err = fmt.Errorf("unsupported kind %s", kind)
} }

View File

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