添加any类型的值

This commit is contained in:
yun
2024-10-28 21:37:58 +08:00
parent aece28fff2
commit becba13ed9
4 changed files with 61 additions and 4 deletions
+31
View File
@@ -0,0 +1,31 @@
package structx_test
import (
"fmt"
"testing"
"code.yun.ink/pkg/structx"
)
func TestAttactToStructMap(t *testing.T) {
m := make(map[string]interface{})
m["name"] = "Tom"
m["age"] = 18
m["is_man"] = true
fmt.Println(m)
d := Data{}
r, err := structx.AttactToStructAny(&d, m)
fmt.Printf("%+v %+v %+v", d, r, err)
}
type Data struct {
Name string `json:"name"`
Age int `json:"age"`
IsMan bool `json:"is_man"`
Addr string `json:"addr"`
}