按功能拆分文件
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.yun.ink/pkg/structx"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
demo1()
|
||||
|
||||
}
|
||||
|
||||
func demo1() {
|
||||
|
||||
p1 := &Person{}
|
||||
updateMap1 := map[string]any{
|
||||
"name": "Alice",
|
||||
"age": 30,
|
||||
"active": true,
|
||||
}
|
||||
p2 := &Person2{}
|
||||
p3 := &Person2{}
|
||||
p4 := &Person2{}
|
||||
p5 := &struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Active bool `json:"active"`
|
||||
}{}
|
||||
p6 := &decimal.Decimal{}
|
||||
|
||||
ch1, err := structx.AttactToStructAny(p1, updateMap1)
|
||||
fmt.Println(ch1, err)
|
||||
fmt.Printf("%+v\n", p1)
|
||||
|
||||
ch, err := structx.AttactToStructAny(p2, updateMap1) // just for compile
|
||||
fmt.Println(ch, err)
|
||||
fmt.Printf("%+v\n", p2)
|
||||
|
||||
ch3, err := structx.AttactToStructAny(p3, updateMap1) // just for compile
|
||||
fmt.Println(ch3, err)
|
||||
fmt.Printf("%+v\n", p3)
|
||||
|
||||
ch4, err := structx.AttactToStructAny(p4, updateMap1) // just for compile
|
||||
fmt.Println(ch4, err)
|
||||
fmt.Printf("%+v\n", p4)
|
||||
|
||||
ch5, err := structx.AttactToStructAny(p5, updateMap1) // just for compile
|
||||
fmt.Println(ch5, err)
|
||||
fmt.Printf("%+v\n", p5)
|
||||
|
||||
ch6, err := structx.AttactToStructAny(p6, updateMap1) // just for compile
|
||||
fmt.Println(ch6, err)
|
||||
fmt.Printf("%+v\n", p6)
|
||||
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
type Person2 struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
Reference in New Issue
Block a user