-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (46 loc) · 1.17 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
package main
import (
"context"
"fmt"
"github.com/rentiansheng/mapper"
)
/***************************
@author: tiansheng.ren
@date: 2022/11/2
@desc:
***************************/
type testCopyStructInline struct {
A string `validate:"required,max=5"`
b string
}
type testCopyStructSrc struct {
Int int
AliasCopy string `json:"alias_copy"`
privateString string
Strings []string
testCopyStructInline
}
type testCopyStructDst struct {
Int int
Copy string `json:"alias_copy"`
privateString string
Strings []string
testCopyStructInline
}
func main() {
src := testCopyStructSrc{
Int: 100,
AliasCopy: "alias copy",
privateString: "private",
Strings: []string{"item", "item"},
testCopyStructInline: testCopyStructInline{
A: "inline a",
b: "inline b private",
},
}
errMsg := "Key: 'testCopyStructDst.testCopyStructInline.A' Error:Field validation for 'A' failed on the 'max' tag"
dst := testCopyStructDst{}
m := mapper.NewMapper(mapper.OptionValidateStruct().CopyPrivate())
err := m.Mapper(context.TODO(), src, &dst)
fmt.Println("error:`"+errMsg+"` ", errMsg == err.Error())
}