1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

refactor: move typemap.go to maputil package and add document for it

This commit is contained in:
dudaodong
2023-04-17 10:36:59 +08:00
parent d4a16534f2
commit 5b11a8b457
10 changed files with 211 additions and 439 deletions

View File

@@ -397,3 +397,39 @@ func ExampleOmitByValues() {
// Output:
// map[a:1 b:2 c:3]
}
func ExampleMapTo() {
type (
Person struct {
Name string `json:"name"`
Age int `json:"age"`
Phone string `json:"phone"`
Addr Address `json:"address"`
}
Address struct {
Street string `json:"street"`
Number int `json:"number"`
}
)
personInfo := map[string]interface{}{
"name": "Nothin",
"age": 28,
"phone": "123456789",
"address": map[string]interface{}{
"street": "test",
"number": 1,
},
}
var p Person
err := MapTo(personInfo, &p)
fmt.Println(err)
fmt.Println(p)
// Output:
// <nil>
// {Nothin 28 123456789 {test 1}}
}