-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
81 lines (71 loc) · 1.58 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"context"
"fmt"
"github.com/rentiansheng/mapper"
)
/***************************
@author: tiansheng.ren
@date: 2022/11/2
@desc:
***************************/
type Copy struct {
F string `json:"json_f" gorm:"column:gorm_f" copy:"copy_f"`
}
type CopyJSON struct {
F string `json:"json_f,copy=json_copy_f" gorm:"column:gorm_f"`
}
type JSON struct {
F string `json:"json_f" gorm:"column:gorm_f"`
}
type GORM struct {
F string `gorm:"column:gorm_f"`
}
type RawField struct {
F string
}
func main() {
ctx := context.Background()
src := map[string]string{
"copy_f": "copy_f",
"json_copy_f": "json_copy_f",
"json_f": "json_f",
"gorm_f": "gorm_f",
"F": "F",
}
resultCopy := Copy{}
err := mapper.Mapper(ctx, src, &resultCopy)
if err != nil {
fmt.Println(err)
return
}
resultJSONCopy := CopyJSON{}
err = mapper.Mapper(ctx, src, &resultJSONCopy)
if err != nil {
fmt.Println(err)
return
}
resultJSON := JSON{}
err = mapper.Mapper(ctx, src, &resultJSON)
if err != nil {
fmt.Println(err)
return
}
resultGORM := GORM{}
err = mapper.Mapper(ctx, src, &resultGORM)
if err != nil {
fmt.Println(err)
return
}
resultRawField := RawField{}
err = mapper.Mapper(ctx, src, &resultRawField)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("copy_f ", "copy_f" == resultCopy.F)
fmt.Println("json_copy_f ", "json_copy_f" == resultJSONCopy.F)
fmt.Println("json_f ", "json_f" == resultJSON.F)
fmt.Println("gorm_f ", "gorm_f" == resultGORM.F)
fmt.Println("F ", "F" == resultRawField.F)
}