gconv examples update

This commit is contained in:
John
2019-01-17 20:32:02 +08:00
parent efe2535977
commit 2ba796de01
2 changed files with 14 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import (
)
func main() {
i := 123
i := 123.456
fmt.Printf("%10s %v\n", "Int:", gconv.Int(i))
fmt.Printf("%10s %v\n", "Int8:", gconv.Int8(i))
fmt.Printf("%10s %v\n", "Int16:", gconv.Int16(i))

View File

@ -11,11 +11,15 @@ func main() {
Name string
Result int
}
type User struct {
type User1 struct {
Scores Score
}
type User2 struct {
Scores *Score
}
user := new(User)
user1 := new(User1)
user2 := new(User2)
scores := map[string]interface{}{
"Scores" : map[string]interface{}{
"Name" : "john",
@ -23,10 +27,14 @@ func main() {
},
}
// 嵌套struct转换
if err := gconv.Struct(scores, user); err != nil {
if err := gconv.Struct(scores, user1); err != nil {
fmt.Println(err)
} else {
g.Dump(user)
g.Dump(user1)
}
if err := gconv.Struct(scores, user2); err != nil {
fmt.Println(err)
} else {
g.Dump(user2)
}
}