1 package funk
2
3 import "database/sql"
4
5 type Model interface {
6 TableName() string
7 }
8
9
10 type Bar struct {
11 Name string `tag_name:"BarName"`
12 Bar *Bar
13 Bars []*Bar
14 }
15
16 func (b Bar) TableName() string {
17 return "bar"
18 }
19
20
21 type Foo struct {
22 ID int
23 FirstName string `tag_name:"tag 1"`
24 LastName string `tag_name:"tag 2"`
25 Age int `tag_name:"tag 3"`
26 Bar *Bar `tag_name:"tag 4"`
27 Bars []*Bar
28 EmptyValue sql.NullInt64
29
30 BarInterface interface{}
31 BarPointer interface{}
32 GeneralInterface interface{}
33
34 ZeroBoolValue bool
35 ZeroIntValue int
36 ZeroIntPtrValue *int
37 }
38
39 func (f Foo) TableName() string {
40 return "foo"
41 }
42
43 var bar = &Bar{
44 Name: "Test",
45 Bars: []*Bar{
46 {
47 Name: "Level1-1",
48 Bar: &Bar{
49 Name: "Level2-1",
50 },
51 },
52 {
53 Name: "Level1-2",
54 Bar: &Bar{
55 Name: "Level2-2",
56 },
57 },
58 },
59 }
60
61 var foo = &Foo{
62 ID: 1,
63 FirstName: "Dark",
64 LastName: "Vador",
65 Age: 30,
66 Bar: bar,
67 EmptyValue: sql.NullInt64{
68 Valid: true,
69 Int64: 10,
70 },
71 Bars: []*Bar{
72 bar,
73 bar,
74 },
75 BarInterface: bar,
76 BarPointer: &bar,
77 ZeroBoolValue: false,
78 ZeroIntValue: 0,
79 ZeroIntPtrValue: nil,
80 }
81
82 var foo2 = &Foo{
83 ID: 1,
84 FirstName: "Dark",
85 LastName: "Vador",
86 Age: 30,
87 }
88
89 var m1 = map[string]interface{}{
90 "id": 1,
91 "firstname": "dark",
92 "lastname": "vador",
93 "age": 30,
94 "bar": map[string]interface{}{
95 "name": "test",
96 "bars": []map[string]interface{}{
97 {
98 "name": "level1-1",
99 "bar": map[string]interface{}{
100 "name": "level2-1",
101 },
102 },
103 {
104 "name": "level1-2",
105 "bar": map[string]interface{}{
106 "name": "level2-2",
107 },
108 },
109 },
110 },
111 }
112
113 var m2 = map[string]interface{}{
114 "id": 1,
115 "firstname": "dark",
116 "lastname": "vador",
117 "age": 30,
118 }
119
120 type FooUnexported struct {
121 unexported bool
122 }
123
124 var fooUnexported = &FooUnexported{
125 unexported: true,
126 }
View as plain text