@@ -10,6 +10,9 @@ type Uint64 uint64
10
10
11
11
// UnmarshalJSON implement json Unmarshal interface
12
12
func (u64 * Uint64 ) UnmarshalJSON (b []byte ) (err error ) {
13
+ if len (b ) == 0 {
14
+ return nil
15
+ }
13
16
if b [0 ] == '"' && b [len (b )- 1 ] == '"' {
14
17
b = b [1 : len (b )- 1 ]
15
18
}
@@ -31,6 +34,9 @@ type Int64 int64
31
34
32
35
// UnmarshalJSON implement json Unmarshal interface
33
36
func (i64 * Int64 ) UnmarshalJSON (b []byte ) (err error ) {
37
+ if len (b ) == 0 {
38
+ return nil
39
+ }
34
40
if b [0 ] == '"' && b [len (b )- 1 ] == '"' {
35
41
b = b [1 : len (b )- 1 ]
36
42
}
@@ -52,6 +58,9 @@ type Int int
52
58
53
59
// UnmarshalJSON implement json Unmarshal interface
54
60
func (i * Int ) UnmarshalJSON (b []byte ) (err error ) {
61
+ if len (b ) == 0 {
62
+ return nil
63
+ }
55
64
if b [0 ] == '"' && b [len (b )- 1 ] == '"' {
56
65
b = b [1 : len (b )- 1 ]
57
66
}
@@ -73,6 +82,9 @@ type Float64 float64
73
82
74
83
// UnmarshalJSON implement json Unmarshal interface
75
84
func (f64 * Float64 ) UnmarshalJSON (b []byte ) (err error ) {
85
+ if len (b ) == 0 {
86
+ return nil
87
+ }
76
88
if b [0 ] == '"' && b [len (b )- 1 ] == '"' {
77
89
b = b [1 : len (b )- 1 ]
78
90
}
@@ -93,3 +105,55 @@ func JSONMarshal(i interface{}) []byte {
93
105
b , _ := json .Marshal (i )
94
106
return b
95
107
}
108
+
109
+ type MatchType int
110
+
111
+ // UnmarshalJSON implement json Unmarshal interface
112
+ func (m * MatchType ) UnmarshalJSON (b []byte ) (err error ) {
113
+ if len (b ) == 0 {
114
+ return nil
115
+ }
116
+ if b [0 ] == '"' && b [len (b )- 1 ] == '"' {
117
+ b = b [1 : len (b )- 1 ]
118
+ }
119
+ if i , err := strconv .ParseFloat (string (b ), 64 ); err == nil {
120
+ * m = MatchType (i )
121
+ } else {
122
+ switch string (b ) {
123
+ case "精确匹配" :
124
+ * m = MatchType (1 )
125
+ case "短语匹配" :
126
+ * m = MatchType (2 )
127
+ case "广泛匹配" :
128
+ * m = MatchType (3 )
129
+ }
130
+ }
131
+ return
132
+ }
133
+
134
+ // UnmarshalCSV implement json Unmarshal interface
135
+ func (m * MatchType ) UnmarshalCSV (b string ) (err error ) {
136
+ if len (b ) == 0 {
137
+ return nil
138
+ }
139
+ if b [0 ] == '"' && b [len (b )- 1 ] == '"' {
140
+ b = b [1 : len (b )- 1 ]
141
+ }
142
+ if i , err := strconv .ParseFloat (b , 64 ); err == nil {
143
+ * m = MatchType (i )
144
+ } else {
145
+ switch b {
146
+ case "精确匹配" :
147
+ * m = MatchType (1 )
148
+ case "短语匹配" :
149
+ * m = MatchType (2 )
150
+ case "广泛匹配" :
151
+ * m = MatchType (3 )
152
+ }
153
+ }
154
+ return
155
+ }
156
+
157
+ func (m MatchType ) Value () int {
158
+ return int (m )
159
+ }
0 commit comments