-
Notifications
You must be signed in to change notification settings - Fork 271
/
funk_test.go
142 lines (122 loc) · 2.07 KB
/
funk_test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package funk
import "database/sql"
type Model interface {
TableName() string
}
// Bar is
type Bar struct {
Name string `tag_name:"BarName"`
Bar *Bar
Bars []*Bar
}
func (b Bar) TableName() string {
return "bar"
}
// Foo is
type Foo struct {
ID int
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`
Age int `tag_name:"tag 3"`
Bar *Bar `tag_name:"tag 4"`
Bars []*Bar
EmptyValue sql.NullInt64
BarInterface interface{}
BarPointer interface{}
GeneralInterface interface{}
ZeroBoolValue bool
ZeroIntValue int
ZeroIntPtrValue *int
}
func (f Foo) TableName() string {
return "foo"
}
var bar = &Bar{
Name: "Test",
Bars: []*Bar{
{
Name: "Level1-1",
Bar: &Bar{
Name: "Level2-1",
},
},
{
Name: "Level1-2",
Bar: &Bar{
Name: "Level2-2",
},
},
},
}
var foo = &Foo{
ID: 1,
FirstName: "Dark",
LastName: "Vador",
Age: 30,
Bar: bar,
EmptyValue: sql.NullInt64{
Valid: true,
Int64: 10,
},
Bars: []*Bar{
bar,
bar,
},
BarInterface: bar,
BarPointer: &bar,
ZeroBoolValue: false,
ZeroIntValue: 0,
ZeroIntPtrValue: nil,
}
var foo2 = &Foo{
ID: 1,
FirstName: "Dark",
LastName: "Vador",
Age: 30,
}
var m1 = map[string]interface{}{
"id": 1,
"firstname": "dark",
"lastname": "vador",
"age": 30,
"bar": map[string]interface{}{
"name": "test",
"bars": []map[string]interface{}{
{
"name": "level1-1",
"bar": map[string]interface{}{
"name": "level2-1",
},
},
{
"name": "level1-2",
"bar": map[string]interface{}{
"name": "level2-2",
},
},
},
},
}
var m2 = map[string]interface{}{
"id": 1,
"firstname": "dark",
"lastname": "vador",
"age": 30,
}
type FooUnexported struct {
unexported bool
}
var fooUnexported = &FooUnexported{
unexported: true,
}
type EmbeddedStruct struct {
EmbeddedField *string
}
type RootStructPointer struct {
*EmbeddedStruct
RootField *string
}
type RootStructNotPointer struct {
EmbeddedStruct
RootField *string
}