Skip to content

Commit 58f1ba5

Browse files
committed
Merge branch 'release/v1.8.2'
2 parents a6f8aa3 + 7cead86 commit 58f1ba5

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

model/report/stat.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package report
22

3+
import "github.com/bububa/kwai-marketing-api/model"
4+
35
// Stat 数据报表
46
type Stat struct {
57
// CampaignID 广告计划ID
@@ -19,7 +21,7 @@ type Stat struct {
1921
// Word 关键词文本
2022
Word string `json:"word,omitempty"`
2123
// MatchType 匹配方式:1:精确匹配,2:短语匹配,3:广泛匹配
22-
MatchType int `json:"match_type,omitempty"`
24+
MatchType model.MatchType `json:"match_type,omitempty"`
2325
// PhotoID 视频id
2426
PhotoID string `json:"photo_id,omitempty"`
2527
// PhotoUrl 视频链接

model/types.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ type Uint64 uint64
1010

1111
// UnmarshalJSON implement json Unmarshal interface
1212
func (u64 *Uint64) UnmarshalJSON(b []byte) (err error) {
13+
if len(b) == 0 {
14+
return nil
15+
}
1316
if b[0] == '"' && b[len(b)-1] == '"' {
1417
b = b[1 : len(b)-1]
1518
}
@@ -31,6 +34,9 @@ type Int64 int64
3134

3235
// UnmarshalJSON implement json Unmarshal interface
3336
func (i64 *Int64) UnmarshalJSON(b []byte) (err error) {
37+
if len(b) == 0 {
38+
return nil
39+
}
3440
if b[0] == '"' && b[len(b)-1] == '"' {
3541
b = b[1 : len(b)-1]
3642
}
@@ -52,6 +58,9 @@ type Int int
5258

5359
// UnmarshalJSON implement json Unmarshal interface
5460
func (i *Int) UnmarshalJSON(b []byte) (err error) {
61+
if len(b) == 0 {
62+
return nil
63+
}
5564
if b[0] == '"' && b[len(b)-1] == '"' {
5665
b = b[1 : len(b)-1]
5766
}
@@ -73,6 +82,9 @@ type Float64 float64
7382

7483
// UnmarshalJSON implement json Unmarshal interface
7584
func (f64 *Float64) UnmarshalJSON(b []byte) (err error) {
85+
if len(b) == 0 {
86+
return nil
87+
}
7688
if b[0] == '"' && b[len(b)-1] == '"' {
7789
b = b[1 : len(b)-1]
7890
}
@@ -93,3 +105,55 @@ func JSONMarshal(i interface{}) []byte {
93105
b, _ := json.Marshal(i)
94106
return b
95107
}
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

Comments
 (0)