mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
42 lines
575 B
Go
42 lines
575 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/util/gconv"
|
|
)
|
|
|
|
func main() {
|
|
type Score struct {
|
|
Name string
|
|
Result int
|
|
}
|
|
type User1 struct {
|
|
Scores Score
|
|
}
|
|
type User2 struct {
|
|
Scores *Score
|
|
}
|
|
|
|
user1 := new(User1)
|
|
user2 := new(User2)
|
|
scores := g.Map{
|
|
"Scores": g.Map{
|
|
"Name": "john",
|
|
"Result": 100,
|
|
},
|
|
}
|
|
|
|
if err := gconv.Struct(scores, user1); err != nil {
|
|
fmt.Println(err)
|
|
} else {
|
|
g.Dump(user1)
|
|
}
|
|
if err := gconv.Struct(scores, user2); err != nil {
|
|
fmt.Println(err)
|
|
} else {
|
|
g.Dump(user2)
|
|
}
|
|
}
|