添加any类型的值
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
Reference in New Issue
Block a user