Browse Source

修复bug

jiantaoli 4 years ago
parent
commit
859727a6b4

+ 6 - 0
.idea/dictionaries/zhanlangpc.xml

@@ -1,11 +1,17 @@
1
 <component name="ProjectDictionaryState">
1
 <component name="ProjectDictionaryState">
2
   <dictionary name="zhanlangpc">
2
   <dictionary name="zhanlangpc">
3
     <words>
3
     <words>
4
+      <w>adip</w>
5
+      <w>ciphertext</w>
6
+      <w>dingtou</w>
4
       <w>imei</w>
7
       <w>imei</w>
8
+      <w>padtext</w>
5
       <w>sadd</w>
9
       <w>sadd</w>
10
+      <w>scard</w>
6
       <w>smembers</w>
11
       <w>smembers</w>
7
       <w>srandmember</w>
12
       <w>srandmember</w>
8
       <w>srem</w>
13
       <w>srem</w>
14
+      <w>weigth</w>
9
     </words>
15
     </words>
10
   </dictionary>
16
   </dictionary>
11
 </component>
17
 </component>

+ 21 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,21 @@
1
+<component name="InspectionProjectProfileManager">
2
+  <profile version="1.0">
3
+    <option name="myName" value="Project Default" />
4
+    <inspection_tool class="GoUnhandledErrorResult" enabled="true" level="WARNING" enabled_by_default="true">
5
+      <methods>
6
+        <method importPath="hash" receiver="Hash" name="Write" />
7
+        <method importPath="strings" receiver="*Builder" name="Write" />
8
+        <method importPath="strings" receiver="*Builder" name="WriteByte" />
9
+        <method importPath="bytes" receiver="*Buffer" name="WriteRune" />
10
+        <method importPath="bytes" receiver="*Buffer" name="Write" />
11
+        <method importPath="bytes" receiver="*Buffer" name="WriteString" />
12
+        <method importPath="strings" receiver="*Builder" name="WriteString" />
13
+        <method importPath="bytes" receiver="*Buffer" name="WriteByte" />
14
+        <method importPath="strings" receiver="*Builder" name="WriteRune" />
15
+        <method importPath="math/rand" receiver="*Rand" name="Read" />
16
+        <method importPath="github.com/gomodule/redigo/redis" receiver="Conn" name="Close" />
17
+        <method importPath="io" receiver="ReadCloser" name="Close" />
18
+      </methods>
19
+    </inspection_tool>
20
+  </profile>
21
+</component>

+ 147 - 63
ads_handler.go

@@ -4,6 +4,7 @@ import (
4
 	"encoding/json"
4
 	"encoding/json"
5
 	"fmt"
5
 	"fmt"
6
 	"github.com/gin-gonic/gin"
6
 	"github.com/gin-gonic/gin"
7
+	"io"
7
 	"math/rand"
8
 	"math/rand"
8
 	"miads/adslib"
9
 	"miads/adslib"
9
 	"miads/adslib/addata"
10
 	"miads/adslib/addata"
@@ -16,9 +17,13 @@ import (
16
 	"miads/adslib/redis_data"
17
 	"miads/adslib/redis_data"
17
 	"miads/adslib/utils"
18
 	"miads/adslib/utils"
18
 	"net/url"
19
 	"net/url"
20
+	"os"
19
 	"strconv"
21
 	"strconv"
20
 	"strings"
22
 	"strings"
21
 	"time"
23
 	"time"
24
+
25
+	"github.com/lestrrat-go/file-rotatelogs"
26
+	log "github.com/sirupsen/logrus"
22
 )
27
 )
23
 
28
 
24
 type Response struct {
29
 type Response struct {
@@ -28,13 +33,39 @@ type Response struct {
28
 	addata.AdData
33
 	addata.AdData
29
 }
34
 }
30
 
35
 
36
+func setupLogger(logName string, logLevel log.Level) {
37
+	writer, err := rotatelogs.New(
38
+		logName+".%Y%m%d",
39
+
40
+		// WithLinkName为最新的日志建立软连接,以方便随着找到当前日志文件
41
+		rotatelogs.WithLinkName(logName),
42
+
43
+		// WithRotationTime设置日志分割的时间,这里设置为一小时分割一次
44
+		rotatelogs.WithRotationTime(time.Hour),
45
+
46
+		// WithMaxAge和WithRotationCount二者只能设置一个,
47
+		// WithMaxAge设置文件清理前的最长保存时间,
48
+		// WithRotationCount设置文件清理前最多保存的个数。
49
+		rotatelogs.WithMaxAge(time.Hour*24*3),
50
+	)
51
+
52
+	if err != nil {
53
+		log.Errorf("config local file system for logger error: %v", err)
54
+	}
55
+
56
+	log.SetReportCaller(true)
57
+	log.SetLevel(logLevel)
58
+	log.SetOutput(io.MultiWriter(writer, os.Stdout))
59
+}
60
+
31
 func adsHandler(c *gin.Context) {
61
 func adsHandler(c *gin.Context) {
62
+	setupLogger("log/ads.log", log.TraceLevel)
32
 	c.Header("Content-Type", "application/json")
63
 	c.Header("Content-Type", "application/json")
33
 
64
 
34
 	request := adslib.Request{}
65
 	request := adslib.Request{}
35
 	request.Parse(c)
66
 	request.Parse(c)
36
 
67
 
37
-	fmt.Printf("%+v\n", request)
68
+	log.Printf("%+v", request)
38
 	advertiser := "xiaomi"
69
 	advertiser := "xiaomi"
39
 	uaClient := request.UaClient
70
 	uaClient := request.UaClient
40
 	// 获取ua
71
 	// 获取ua
@@ -111,7 +142,9 @@ func adsHandler(c *gin.Context) {
111
 		graylog.Log(grayLogData)
142
 		graylog.Log(grayLogData)
112
 	}
143
 	}
113
 
144
 
145
+	// 定制city code
114
 	cityCode, err := city.GetCityCode(ipInfo.City)
146
 	cityCode, err := city.GetCityCode(ipInfo.City)
147
+	log.Infof("got city code: %d", cityCode)
115
 	if err != nil {
148
 	if err != nil {
116
 		c.String(404, "get city code failed: %s", err)
149
 		c.String(404, "get city code failed: %s", err)
117
 		return
150
 		return
@@ -131,11 +164,12 @@ func adsHandler(c *gin.Context) {
131
 		// 频率控制
164
 		// 频率控制
132
 		freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
165
 		freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
133
 		if err != nil {
166
 		if err != nil {
167
+			log.Errorf("get freq control conf failed: %s", err)
134
 			c.String(404, "get freq control conf failed: %s", err)
168
 			c.String(404, "get freq control conf failed: %s", err)
135
 			return
169
 			return
136
 		}
170
 		}
137
 
171
 
138
-		fmt.Printf("freq control conf: %+v\n", freqControlConf)
172
+		log.Infof("freq control conf: %+v", freqControlConf)
139
 		hour, _ := strconv.Atoi(time.Now().Format("01"))
173
 		hour, _ := strconv.Atoi(time.Now().Format("01"))
140
 		tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
174
 		tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
141
 		if ok {
175
 		if ok {
@@ -153,16 +187,17 @@ func adsHandler(c *gin.Context) {
153
 	needControl := false
187
 	needControl := false
154
 	if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
188
 	if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
155
 		// 需要凭空
189
 		// 需要凭空
190
+		log.Infof("need control: %d", lastReqTime)
156
 		needControl = true
191
 		needControl = true
157
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
192
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
158
 	} else {
193
 	} else {
159
 		device.SetIpReqTime(ip, time.Now().Unix())
194
 		device.SetIpReqTime(ip, time.Now().Unix())
160
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
195
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
161
 	}
196
 	}
162
-
163
 	//### 检查是否是ip黑名单
197
 	//### 检查是否是ip黑名单
164
 	isIpBlack, err := ads_checker.CheckBlackIp(ip)
198
 	isIpBlack, err := ads_checker.CheckBlackIp(ip)
165
 	if err != nil {
199
 	if err != nil {
200
+		log.Errorf("check black ip failed: %s", err)
166
 		c.String(404, "check black ip failed: %s", err)
201
 		c.String(404, "check black ip failed: %s", err)
167
 		return
202
 		return
168
 	}
203
 	}
@@ -174,6 +209,7 @@ func adsHandler(c *gin.Context) {
174
 	// 获取渠道的黑白性
209
 	// 获取渠道的黑白性
175
 	reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
210
 	reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
176
 	if err != nil {
211
 	if err != nil {
212
+		log.Errorf("get req channel flag failed: %s", err)
177
 		c.String(404, "get req channel flag failed: %s", err)
213
 		c.String(404, "get req channel flag failed: %s", err)
178
 		return
214
 		return
179
 	}
215
 	}
@@ -205,10 +241,12 @@ func adsHandler(c *gin.Context) {
205
 		randomNum := 3
241
 		randomNum := 3
206
 		deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
242
 		deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
207
 		if err != nil {
243
 		if err != nil {
208
-			c.String(404, "get req channel flag failed")
244
+			log.Errorf("get mi device conf failed: %s", err)
245
+			c.String(404, "get mi device conf failed: %s", err)
209
 			return
246
 			return
210
 		}
247
 		}
211
 		if deviceConf != nil {
248
 		if deviceConf != nil {
249
+			log.Infof("use cache imei: %+v", deviceConf)
212
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
250
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
213
 			imei = deviceConf.Imei
251
 			imei = deviceConf.Imei
214
 			uaClient = deviceConf.Ua
252
 			uaClient = deviceConf.Ua
@@ -228,7 +266,8 @@ func adsHandler(c *gin.Context) {
228
 				fakeImei := ""
266
 				fakeImei := ""
229
 				fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
267
 				fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
230
 				if err != nil {
268
 				if err != nil {
231
-					c.String(404, "get device conf failed")
269
+					log.Errorf("get device conf failed: %s", err)
270
+					c.String(404, "get device conf failed: %s", err)
232
 					return
271
 					return
233
 				}
272
 				}
234
 
273
 
@@ -237,7 +276,10 @@ func adsHandler(c *gin.Context) {
237
 				replaceUa := ""
276
 				replaceUa := ""
238
 				if fakeDeviceConf != nil {
277
 				if fakeDeviceConf != nil {
239
 					device.SetAdsTagLog(advertiser, request.ReqSource, "DS_REPL", cityCode)
278
 					device.SetAdsTagLog(advertiser, request.ReqSource, "DS_REPL", cityCode)
240
-					device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
279
+					err := device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
280
+					if err != nil {
281
+						log.Errorf("set mi device conf failed: %s", err)
282
+					}
241
 					imei = fakeDeviceConf.Imei
283
 					imei = fakeDeviceConf.Imei
242
 					uaClient = fakeDeviceConf.Ua
284
 					uaClient = fakeDeviceConf.Ua
243
 					originImei = fakeDeviceConf.OriginImei
285
 					originImei = fakeDeviceConf.OriginImei
@@ -283,6 +325,7 @@ func adsHandler(c *gin.Context) {
283
 		// 解码ua_client
325
 		// 解码ua_client
284
 		uaClient, _ = url.QueryUnescape(uaClient)
326
 		uaClient, _ = url.QueryUnescape(uaClient)
285
 	} else if request.IsMiDevice() {
327
 	} else if request.IsMiDevice() {
328
+		log.Info("real mi")
286
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
329
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
287
 		userFlag = 3
330
 		userFlag = 3
288
 		sendPhoneType = 1
331
 		sendPhoneType = 1
@@ -291,14 +334,18 @@ func adsHandler(c *gin.Context) {
291
 	// 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
334
 	// 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
292
 	isBlackImei, err := device.CheckIsBlackImei(imei, false)
335
 	isBlackImei, err := device.CheckIsBlackImei(imei, false)
293
 	if err != nil {
336
 	if err != nil {
294
-		c.String(404, "get device conf failed")
337
+		log.Errorf("get device conf failed: %s", err)
338
+		c.String(404, "get device conf failed: %s", err)
295
 		return
339
 		return
296
 	}
340
 	}
297
 
341
 
342
+	log.Tracef("replace flag: %d", replaceFlag)
298
 	if isBlackImei {
343
 	if isBlackImei {
299
 		if replaceFlag == 1 {
344
 		if replaceFlag == 1 {
345
+			log.Trace("replace")
300
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
346
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
301
 		} else {
347
 		} else {
348
+			log.Trace("not replace")
302
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
349
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
303
 		}
350
 		}
304
 	}
351
 	}
@@ -337,6 +384,7 @@ func adsHandler(c *gin.Context) {
337
 	}
384
 	}
338
 
385
 
339
 	dspInfo.RealMd5Imei = md5Imei
386
 	dspInfo.RealMd5Imei = md5Imei
387
+	log.Infof("dsp: %+v", dspInfo)
340
 	//ads_item = None
388
 	//ads_item = None
341
 	//xiaomi_response = []
389
 	//xiaomi_response = []
342
 	hour, _ := strconv.Atoi(time.Now().Format("01"))
390
 	hour, _ := strconv.Atoi(time.Now().Format("01"))
@@ -349,17 +397,27 @@ func adsHandler(c *gin.Context) {
349
 		}
397
 		}
350
 	}
398
 	}
351
 
399
 
400
+	log.Infof("can request: %t", canRequest)
401
+
352
 	var adData *addata.AdData
402
 	var adData *addata.AdData
353
 
403
 
354
 	// 非频率控制,设备黑名单,ip黑名单,白名单渠道,并且替换了小米设备的
404
 	// 非频率控制,设备黑名单,ip黑名单,白名单渠道,并且替换了小米设备的
355
 	if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
405
 	if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
356
 		adData, err = addata.GetAdsInfos(&dspInfo, advertiser)
406
 		adData, err = addata.GetAdsInfos(&dspInfo, advertiser)
407
+		if err != nil {
408
+			log.Errorf("get mi ad data failed: %s", err)
409
+			c.String(404, "get mi ad data failed: %s", err)
410
+			return
411
+		}
412
+		log.Infof("get mi ads data: %+v", adData)
357
 	}
413
 	}
358
 
414
 
359
-	canMixFlag := 0
415
+	canMixFlag := 1
360
 	xiaomiResponseFlag := 0
416
 	xiaomiResponseFlag := 0
361
 	response := Response{}
417
 	response := Response{}
418
+	response.Msg = "ok"
362
 	if adData != nil && len(adData.TargetAddition) > 1 {
419
 	if adData != nil && len(adData.TargetAddition) > 1 {
420
+		log.Infof("add target js order")
363
 		xiaomiResponseFlag = 1
421
 		xiaomiResponseFlag = 1
364
 		realTarget := ""
422
 		realTarget := ""
365
 		if adData.Target != "" {
423
 		if adData.Target != "" {
@@ -372,7 +430,13 @@ func adsHandler(c *gin.Context) {
372
 			redis_data.SetSkipInfo(md5Skip, adData.Target)
430
 			redis_data.SetSkipInfo(md5Skip, adData.Target)
373
 		}
431
 		}
374
 		adData.Target = realTarget
432
 		adData.Target = realTarget
375
-		adData.JsOrderId, _ = redis_data.GetMinScriptOrderByAdv(advertiser)
433
+		adData.JsOrderId, err = redis_data.GetMinScriptOrderByAdv(advertiser)
434
+		if err != nil {
435
+			log.Errorf("get min script order by adv failed: %s", err)
436
+			c.String(404, "get min script order by adv failed: %s", err)
437
+			return
438
+		}
439
+		log.Infof("got min script order: %d", adData.JsOrderId)
376
 		adData.UserAgent = uaClient
440
 		adData.UserAgent = uaClient
377
 
441
 
378
 		if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
442
 		if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
@@ -385,21 +449,21 @@ func adsHandler(c *gin.Context) {
385
 			device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET_1", cityCode) // 广告获取成功
449
 			device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET_1", cityCode) // 广告获取成功
386
 		}
450
 		}
387
 		device.SetAdsTagLog(advertiser, dspInfo.ReqSource, fmt.Sprintf("ADS_USER_%d", userFlag), cityCode) //  广告类型,缓存,新用户,小米手机
451
 		device.SetAdsTagLog(advertiser, dspInfo.ReqSource, fmt.Sprintf("ADS_USER_%d", userFlag), cityCode) //  广告类型,缓存,新用户,小米手机
388
-		// 判断这个渠道是否要去融合和融合的流量占比
389
-		mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
390
-		if err != nil {
391
-			c.String(404, "get device conf failed")
392
-			return
393
-		}
452
+		// // 判断这个渠道是否要去融合和融合的流量占比
453
+		// mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
454
+		// if err != nil {
455
+		// 	log.Errorf("get device conf failed: %s", err)
456
+		// 	c.String(404, "get device conf failed: %s", err)
457
+		// 	return
458
+		// }
394
 		flowRandomNum = rand.Intn(100)
459
 		flowRandomNum = rand.Intn(100)
395
-		isOverFlow := false
396
-		//flow_flag = 0
397
-		if flowRandomNum > mixChannelFlag.Weigth {
398
-			isOverFlow = true
399
-		}
400
-		if mixChannelFlag.ChannelFlag != 1 || isOverFlow {
401
-			//extra_infos = []
402
-		}
460
+		//isOverFlow := false
461
+		//if flowRandomNum > mixChannelFlag.Weigth {
462
+		//	isOverFlow = true
463
+		//}
464
+		//if mixChannelFlag.ChannelFlag != 1 || isOverFlow {
465
+		//	//extra_infos = []
466
+		//}
403
 
467
 
404
 		// 组装返回去的action
468
 		// 组装返回去的action
405
 		serverActionResponse := map[string]int{"server_view": 0, "server_click": 0, "server_close": 0, "server_video_finish": 0, "server_video_timer": 0}
469
 		serverActionResponse := map[string]int{"server_view": 0, "server_click": 0, "server_close": 0, "server_video_finish": 0, "server_video_timer": 0}
@@ -417,27 +481,33 @@ func adsHandler(c *gin.Context) {
417
 				serverActionResponse["server_video_timer"] = 1
481
 				serverActionResponse["server_video_timer"] = 1
418
 			}
482
 			}
419
 		}
483
 		}
420
-
484
+		log.Infof("server action response: %+v", serverActionResponse)
421
 		// 增加跟随订单
485
 		// 增加跟随订单
422
 		if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
486
 		if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
423
-			adData, err = addata.CombineOrderBy(adData, advertiser, &dspInfo)
487
+			log.Infof("add more order")
488
+			adData, err = addata.CombineOrderBy(adData, &dspInfo)
424
 			if err != nil {
489
 			if err != nil {
490
+				log.Errorf("combine order failed: %s", err)
425
 				c.String(404, "combine order failed: %s", err.Error())
491
 				c.String(404, "combine order failed: %s", err.Error())
426
 				return
492
 				return
427
 			}
493
 			}
494
+			log.Infof("get custom order: %+v", adData)
428
 		}
495
 		}
429
 
496
 
430
 		//# 检查最后是否有click
497
 		//# 检查最后是否有click
431
-		//last_target_addition_infos = ads_item_new.get('target_addition',[])
498
+		log.Infof("check ads item new: %+v", adData)
499
+
432
 		for _, targetAddition := range adData.TargetAddition {
500
 		for _, targetAddition := range adData.TargetAddition {
433
 			if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
501
 			if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
502
+				log.Infof("can't mix, targetAddition: %+v", targetAddition)
434
 				canMixFlag = 0
503
 				canMixFlag = 0
435
 				break
504
 				break
436
 			}
505
 			}
437
 		}
506
 		}
438
 
507
 
439
 		if request.NewAdsFlag == 0 {
508
 		if request.NewAdsFlag == 0 {
440
-			//response.update(ads_item_new)
509
+			response.AdData = *adData
510
+			log.Infof("update response: +%v", response)
441
 		} else {
511
 		} else {
442
 			jsonBytes, err := json.Marshal(*adData)
512
 			jsonBytes, err := json.Marshal(*adData)
443
 			if err != nil {
513
 			if err != nil {
@@ -448,6 +518,8 @@ func adsHandler(c *gin.Context) {
448
 			response.AdsResult = encryptData
518
 			response.AdsResult = encryptData
449
 		}
519
 		}
450
 	}
520
 	}
521
+
522
+	log.Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
451
 	if canMixFlag == 1 {
523
 	if canMixFlag == 1 {
452
 		response.Result = 2
524
 		response.Result = 2
453
 		response.Msg = "no ads"
525
 		response.Msg = "no ads"
@@ -458,15 +530,17 @@ func adsHandler(c *gin.Context) {
458
 		// 增加打底广告
530
 		// 增加打底广告
459
 		if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needControl && !isBlackImei {
531
 		if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needControl && !isBlackImei {
460
 			shortMessage := "kong"
532
 			shortMessage := "kong"
461
-			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 0, xiaomiResponseFlag)
533
+			// 先跑定投
534
+			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, 0, 0, xiaomiResponseFlag)
462
 			if err != nil {
535
 			if err != nil {
463
 				c.String(404, "get custom ads info failed: %s", err.Error())
536
 				c.String(404, "get custom ads info failed: %s", err.Error())
464
 				return
537
 				return
465
 			}
538
 			}
539
+			log.Infof("dingtou: %+v", customAdData)
466
 
540
 
467
 			// 定投没有就跑其他的
541
 			// 定投没有就跑其他的
468
 			if customAdData == nil {
542
 			if customAdData == nil {
469
-				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 1, xiaomiResponseFlag)
543
+				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, 0, 1, xiaomiResponseFlag)
470
 				if err != nil {
544
 				if err != nil {
471
 					c.String(404, "get fix custom ads info failed: %s", err.Error())
545
 					c.String(404, "get fix custom ads info failed: %s", err.Error())
472
 					return
546
 					return
@@ -478,9 +552,9 @@ func adsHandler(c *gin.Context) {
478
 			}
552
 			}
479
 
553
 
480
 			if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
554
 			if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
481
-				adDataBytes, err := json.Marshal(*adData)
555
+				adDataBytes, err := json.Marshal(*customAdData)
482
 				if err != nil {
556
 				if err != nil {
483
-					fmt.Sprintf("marshal addata failed: %s\n", err)
557
+					log.Errorf("marshal adData failed: %s\n", err)
484
 				}
558
 				}
485
 				grayLogData := struct {
559
 				grayLogData := struct {
486
 					Ip           string
560
 					Ip           string
@@ -508,43 +582,44 @@ func adsHandler(c *gin.Context) {
508
 				if len(response.TargetAddition) != 0 && len(customAdData.TargetAddition) != 0 {
582
 				if len(response.TargetAddition) != 0 && len(customAdData.TargetAddition) != 0 {
509
 					rspTargetAddition = response.TargetAddition
583
 					rspTargetAddition = response.TargetAddition
510
 					lastAdData.UserAgent = response.UserAgent
584
 					lastAdData.UserAgent = response.UserAgent
511
-				}
512
-				//  当只有view的时候
513
-				if len(customAdData.TargetAddition) == 1 {
514
-					for _, url := range customAdData.TargetAddition[0].Urls {
515
-						rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
516
-					}
517
-				} else {
518
-					// 当自由订单有view和click的时候
519
-					for _, url := range customAdData.TargetAddition[0].Urls {
520
-						rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, url)
585
+					//  当只有view的时候
586
+					if len(customAdData.TargetAddition) == 1 {
587
+						for _, targetUrl := range customAdData.TargetAddition[0].Urls {
588
+							rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, targetUrl)
589
+						}
590
+					} else {
591
+						// 当自由订单有view和click的时候
592
+						for _, targetUrl := range customAdData.TargetAddition[0].Urls {
593
+							rspTargetAddition[0].Urls = append(rspTargetAddition[0].Urls, targetUrl)
594
+						}
595
+
596
+						for _, targetUrl := range customAdData.TargetAddition[1].Urls {
597
+							rspTargetAddition[1].Urls = append(rspTargetAddition[1].Urls, targetUrl)
598
+						}
599
+						rspTargetAddition[1].Type = "CLICK"
521
 					}
600
 					}
601
+					lastAdData.Target = customAdData.Target
602
+					lastAdData.JsOrderId = customAdData.JsOrderId
603
+					lastAdData.TargetAddition = rspTargetAddition
604
+					lastAdData.DpReport = response.DpReport
605
+					lastAdData.Dp = response.Dp
522
 
606
 
523
-					for _, url := range customAdData.TargetAddition[1].Urls {
524
-						rspTargetAddition[1].Urls = append(rspTargetAddition[1].Urls, url)
607
+					adDataBytes, err := json.Marshal(lastAdData)
608
+					if err != nil {
609
+						log.Errorf("marshal adData failed: %s", err)
610
+					}
611
+					grayLogData := struct {
612
+						ShortMessage string `json:"short_message"`
613
+						ResponseVast string `json:"response_vast"`
614
+					}{
615
+						ShortMessage: "third_mix_xiaomi",
616
+						ResponseVast: string(adDataBytes),
525
 					}
617
 					}
526
-					rspTargetAddition[1].Type = "CLICK"
527
-				}
528
-				lastAdData.Target = customAdData.Target
529
-				lastAdData.JsOrderId = customAdData.JsOrderId
530
-				lastAdData.TargetAddition = rspTargetAddition
531
-				lastAdData.DpReport = response.DpReport
532
-				lastAdData.Dp = response.Dp
533
 
618
 
534
-				adDataBytes, err := json.Marshal(lastAdData)
535
-				if err != nil {
536
-					fmt.Sprintf("marshal addata failed: %s\n", err)
619
+					graylog.Log(grayLogData)
620
+					log.Infof("replace addata: %+v", lastAdData)
621
+					customAdData = &lastAdData
537
 				}
622
 				}
538
-				grayLogData := struct {
539
-					ShortMessage string `json:"short_message"`
540
-					ResponseVast string `json:"response_vast"`
541
-				}{
542
-					ShortMessage: "third_mix_xiaomi",
543
-					ResponseVast: string(adDataBytes),
544
-				}
545
-
546
-				graylog.Log(grayLogData)
547
-				customAdData = &lastAdData
548
 			}
623
 			}
549
 			if customAdData != nil {
624
 			if customAdData != nil {
550
 				device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_HAVE", cityCode) // 广告获取成功
625
 				device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_HAVE", cityCode) // 广告获取成功
@@ -552,19 +627,27 @@ func adsHandler(c *gin.Context) {
552
 					response.Result = 0
627
 					response.Result = 0
553
 					response.Msg = "ok"
628
 					response.Msg = "ok"
554
 
629
 
630
+					log.Infof("rsp1: %+v", customAdData)
555
 					jsonBytes, err := json.Marshal(customAdData)
631
 					jsonBytes, err := json.Marshal(customAdData)
556
 					if err != nil {
632
 					if err != nil {
557
 						c.String(404, "marsha custom addata failed: %s", err.Error())
633
 						c.String(404, "marsha custom addata failed: %s", err.Error())
558
 						return
634
 						return
559
 					}
635
 					}
636
+					log.Infof("rsp1: %s", jsonBytes)
560
 					encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
637
 					encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
561
 					response.AdsResult = encryptData
638
 					response.AdsResult = encryptData
639
+
640
+					log.Infof("encrypt: %s", encryptData)
641
+					s, err := encrypt.Decrypt(encryptData, []byte(adslib.GetConf().SecretKey))
642
+					log.Info(s, err)
643
+
562
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
644
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
563
 					rspBytes, err := json.Marshal(response)
645
 					rspBytes, err := json.Marshal(response)
564
 					if err != nil {
646
 					if err != nil {
565
 						c.String(404, "marshal Response failed: %s", err.Error())
647
 						c.String(404, "marshal Response failed: %s", err.Error())
566
 						return
648
 						return
567
 					}
649
 					}
650
+					log.Infof("rsp1: %s", rspBytes)
568
 					c.String(200, string(rspBytes))
651
 					c.String(200, string(rspBytes))
569
 					return
652
 					return
570
 				} else {
653
 				} else {
@@ -593,5 +676,6 @@ func adsHandler(c *gin.Context) {
593
 		graylog.ReportGrayLog(request, dspInfo, 0, 0)
676
 		graylog.ReportGrayLog(request, dspInfo, 0, 0)
594
 	}
677
 	}
595
 	device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
678
 	device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
679
+	log.Infof("rsp3: %s", rspBytes)
596
 	c.String(200, string(rspBytes))
680
 	c.String(200, string(rspBytes))
597
 }
681
 }

+ 28 - 14
adslib/addata/custom.go

@@ -2,6 +2,7 @@ package addata
2
 
2
 
3
 import (
3
 import (
4
 	"fmt"
4
 	"fmt"
5
+	log "github.com/sirupsen/logrus"
5
 	"math/rand"
6
 	"math/rand"
6
 	"miads/adslib"
7
 	"miads/adslib"
7
 	"miads/adslib/redis_data"
8
 	"miads/adslib/redis_data"
@@ -11,8 +12,8 @@ import (
11
 	"time"
12
 	"time"
12
 )
13
 )
13
 
14
 
14
-func CombineOrderBy(adData *AdData, advertiser string, dsp *utils.DspParam) (*AdData, error) {
15
-	customAdData, err := GetCustomAdsInfos(dsp, advertiser, 1, 0, 0)
15
+func CombineOrderBy(adData *AdData, dsp *utils.DspParam) (*AdData, error) {
16
+	customAdData, err := GetCustomAdsInfos(dsp, 1, 0, 0)
16
 	if err != nil {
17
 	if err != nil {
17
 		return adData, err
18
 		return adData, err
18
 	}
19
 	}
@@ -47,7 +48,7 @@ func CombineOrderBy(adData *AdData, advertiser string, dsp *utils.DspParam) (*Ad
47
 }
48
 }
48
 
49
 
49
 // 获取一个广告
50
 // 获取一个广告
50
-func getOneAds(dsp *utils.DspParam, orderType int, fixFlag int) (*redis_data.AdOrderInfo, error) {
51
+func GetOneAds(dsp *utils.DspParam, orderType int, fixFlag int) (*redis_data.AdOrderInfo, error) {
51
 	// 取出广告
52
 	// 取出广告
52
 	orders, err := redis_data.GetOrderInfos(dsp, fixFlag)
53
 	orders, err := redis_data.GetOrderInfos(dsp, fixFlag)
53
 	if err != nil {
54
 	if err != nil {
@@ -127,31 +128,33 @@ func getNeedDispatchCount(adData *redis_data.AdOrderInfo) (int, error) {
127
 		endMinute = endMinute - 1440 + 2
128
 		endMinute = endMinute - 1440 + 2
128
 	}
129
 	}
129
 
130
 
130
-	key = "time_all_count_" + strconv.Itoa(endMinute)
131
+	endKey := "time_all_count_" + strconv.Itoa(endMinute)
131
 	if adData.LineType == 1 {
132
 	if adData.LineType == 1 {
132
 		// 定制曲线
133
 		// 定制曲线
133
-		key = fmt.Sprintf("time_all_count_%d_%d", adData.OrderID, endMinute)
134
+		endKey = fmt.Sprintf("time_all_count_%d_%d", adData.OrderID, endMinute)
134
 	}
135
 	}
135
 
136
 
136
-	endRemainDispatchCnt, err := redis_data.GetRemainDispatchCount(key)
137
+	endRemainDispatchCnt, err := redis_data.GetRemainDispatchCount(endKey)
137
 	if err != nil {
138
 	if err != nil {
138
 		return 0, err
139
 		return 0, err
139
 	}
140
 	}
140
-
141
+	log.Infof("begin need dispatch count key: %s, %d, end: %s, %d", key, beginRemainDispatchCount, endKey, endRemainDispatchCnt)
141
 	// 结束的剩余值 - 起始剩余值 = 获取区间能跑的值
142
 	// 结束的剩余值 - 起始剩余值 = 获取区间能跑的值
142
 	needDispatchCount := beginRemainDispatchCount - endRemainDispatchCnt
143
 	needDispatchCount := beginRemainDispatchCount - endRemainDispatchCnt
143
 	return needDispatchCount, nil
144
 	return needDispatchCount, nil
144
 }
145
 }
145
 
146
 
146
-func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fixFlag int, xiaomiHasFlag int) (*AdData, error) {
147
-	order, err := getOneAds(dsp, orderType, fixFlag)
147
+func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHasFlag int) (*AdData, error) {
148
+	order, err := GetOneAds(dsp, orderType, fixFlag)
148
 	if err != nil {
149
 	if err != nil {
150
+		log.Errorf("get one ads failed: %s", err)
149
 		return nil, err
151
 		return nil, err
150
 	}
152
 	}
151
 	if order == nil {
153
 	if order == nil {
152
 		return nil, nil
154
 		return nil, nil
153
 	}
155
 	}
154
 
156
 
157
+	log.Infof("begin got custom ad info, xiaomi has flag: %d", xiaomiHasFlag)
155
 	if xiaomiHasFlag == 1 {
158
 	if xiaomiHasFlag == 1 {
156
 		if strings.Index(order.Title, "_ios") > 0 {
159
 		if strings.Index(order.Title, "_ios") > 0 {
157
 			return nil, nil
160
 			return nil, nil
@@ -176,9 +179,9 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
176
 		return nil, err
179
 		return nil, err
177
 	}
180
 	}
178
 
181
 
179
-	fmt.Sprintf("finish show cnt: %d\n", finishShowCnt)
180
 	redis_data.SetPlanDispatchCount(order.OrderID, "show", needDispatchCnt, curTime)
182
 	redis_data.SetPlanDispatchCount(order.OrderID, "show", needDispatchCnt, curTime)
181
 
183
 
184
+	log.Infof("all count: %d, over kpi: %d, show kpi: %d", needDispatchCnt, finishShowCnt, order.ShowKpi)
182
 	// 计算曲线比例
185
 	// 计算曲线比例
183
 	rate := float32(order.ShowKpi) / float32(needDispatchCnt)
186
 	rate := float32(order.ShowKpi) / float32(needDispatchCnt)
184
 
187
 
@@ -192,6 +195,8 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
192
 	if err != nil {
195
 	if err != nil {
193
 		return nil, err
196
 		return nil, err
194
 	}
197
 	}
198
+	log.Infof("line value: %d, rate: %f", lineValue, rate)
199
+
195
 	// 当前分钟需要放出去的数量
200
 	// 当前分钟需要放出去的数量
196
 	curMinuteNeedDispatchCnt := int(float32(lineValue) * rate)
201
 	curMinuteNeedDispatchCnt := int(float32(lineValue) * rate)
197
 	if curMinuteNeedDispatchCnt < 1 {
202
 	if curMinuteNeedDispatchCnt < 1 {
@@ -200,8 +205,11 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
200
 
205
 
201
 	redis_data.SetOrderPlanDispatchCount(order.OrderID, "show", curMinuteNeedDispatchCnt, curTime)
206
 	redis_data.SetOrderPlanDispatchCount(order.OrderID, "show", curMinuteNeedDispatchCnt, curTime)
202
 
207
 
208
+	log.Infof("tt thirds: %+v", order)
203
 	// 获取当前分钟已经完成的下发
209
 	// 获取当前分钟已经完成的下发
204
 	curMinuteFinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
210
 	curMinuteFinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
211
+
212
+	log.Infof("o value: %d, w value: %d", curMinuteFinishedDispatchCnt, curMinuteNeedDispatchCnt)
205
 	if curMinuteFinishedDispatchCnt < curMinuteNeedDispatchCnt {
213
 	if curMinuteFinishedDispatchCnt < curMinuteNeedDispatchCnt {
206
 		data := AdData{
214
 		data := AdData{
207
 			Duration:  5,
215
 			Duration:  5,
@@ -227,6 +235,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
227
 		if strings.Index(order.Title, "_ios") != -1 {
235
 		if strings.Index(order.Title, "_ios") != -1 {
228
 			iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
236
 			iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
229
 			if err != nil {
237
 			if err != nil {
238
+				log.Errorf("get ios ua imei failed: %s", err)
230
 				return nil, err
239
 				return nil, err
231
 			}
240
 			}
232
 			if iosUa != "" {
241
 			if iosUa != "" {
@@ -261,6 +270,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
261
 			if r < 40 && xiaomiHasFlag == 0 {
270
 			if r < 40 && xiaomiHasFlag == 0 {
262
 				iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
271
 				iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
263
 				if err != nil {
272
 				if err != nil {
273
+					log.Errorf("get ios ua imei failed: %s", err)
264
 					return nil, err
274
 					return nil, err
265
 				}
275
 				}
266
 				if iosUa != "" {
276
 				if iosUa != "" {
@@ -310,19 +320,23 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
310
 
320
 
311
 		r := rand.Intn(1000)
321
 		r := rand.Intn(1000)
312
 		clickRate := int(float32(order.ClickKpi) / float32(order.ShowKpi) * 1000)
322
 		clickRate := int(float32(order.ClickKpi) / float32(order.ShowKpi) * 1000)
323
+		log.Infof("rand: %d, rate: %d", r, clickRate)
313
 		if r < clickRate {
324
 		if r < clickRate {
314
 			//下发点击
325
 			//下发点击
315
 			addi = genMonitorAction("CLICK", order.Title, dsp.ReqSource, clickUrl)
326
 			addi = genMonitorAction("CLICK", order.Title, dsp.ReqSource, clickUrl)
316
 			data.TargetAddition = append(data.TargetAddition, *addi)
327
 			data.TargetAddition = append(data.TargetAddition, *addi)
317
 			md5Skip := utils.Md5(targetUrl)
328
 			md5Skip := utils.Md5(targetUrl)
318
-			redis_data.IncrFinishedDispatchCount(order.OrderID, "click", 1, curTime)
329
+			_, err = redis_data.IncrFinishedDispatchCount(order.OrderID, "click", 1, curTime)
330
+			if err != nil {
331
+				log.Errorf("incr finished dispatch count failed: %s", err)
332
+			}
319
 			realTarget := adslib.GetConf().Host + fmt.Sprintf("?action=LOADING&req_source=%s&advertiser=%s&skip=%s&skip_other=%s",
333
 			realTarget := adslib.GetConf().Host + fmt.Sprintf("?action=LOADING&req_source=%s&advertiser=%s&skip=%s&skip_other=%s",
320
-				dsp.ReqSource, "", order.Title, md5Skip)
334
+				dsp.ReqSource, order.Title, "", md5Skip)
321
 			// 塞入缓存中
335
 			// 塞入缓存中
322
 			redis_data.SetSkipInfo(md5Skip, targetUrl)
336
 			redis_data.SetSkipInfo(md5Skip, targetUrl)
323
 			data.Target = realTarget
337
 			data.Target = realTarget
324
-			return &data, nil
325
 		}
338
 		}
339
+		return &data, nil
326
 	}
340
 	}
327
 
341
 
328
 	return nil, nil
342
 	return nil, nil
@@ -345,7 +359,7 @@ func genMonitorAction(action string, title string, reqSource string, url string)
345
 	}
359
 	}
346
 	urlHost := adslib.GetConf().HostIos
360
 	urlHost := adslib.GetConf().HostIos
347
 	actionUrl := fmt.Sprintf("%s?action=%s&advertiser=%s&req_source=%s",
361
 	actionUrl := fmt.Sprintf("%s?action=%s&advertiser=%s&req_source=%s",
348
-		urlHost, action, reqSource, title)
362
+		urlHost, action, title, reqSource)
349
 	adAction.Urls = append(adAction.Urls, actionUrl)
363
 	adAction.Urls = append(adAction.Urls, actionUrl)
350
 	return &adAction
364
 	return &adAction
351
 }
365
 }

+ 28 - 35
adslib/addata/xiaomi.go

@@ -3,6 +3,7 @@ package addata
3
 import (
3
 import (
4
 	"encoding/json"
4
 	"encoding/json"
5
 	"fmt"
5
 	"fmt"
6
+	log "github.com/sirupsen/logrus"
6
 	"html"
7
 	"html"
7
 	"io/ioutil"
8
 	"io/ioutil"
8
 	"math/rand"
9
 	"math/rand"
@@ -63,17 +64,17 @@ type AdInfo struct {
63
 
64
 
64
 type AdData struct {
65
 type AdData struct {
65
 	TargetAddition []AdAction `json:"target_addition"`
66
 	TargetAddition []AdAction `json:"target_addition"`
66
-	Target         string
67
-	ImageUrl       string `json:"image_url"`
68
-	Duration       int64
69
-	VideoUrl       string `json:"video_url"`
70
-	JsOrderId      int64  `json:"js_order_id"`
71
-	UserAgent      string `json:"user_agent"`
72
-	DpReport       string `json:"dp_report"`
73
-	Dp             string `json:"dp"`
74
-	OrderName      string `json:"order_name"`
75
-	Result         int    `json:"result"`
76
-	Msg            string `json:"msg"`
67
+	Target         string     `json:"target"`
68
+	ImageUrl       string     `json:"image_url"`
69
+	Duration       int64      `json:"duration"`
70
+	VideoUrl       string     `json:"video_url"`
71
+	JsOrderId      int64      `json:"js_order_id"`
72
+	UserAgent      string     `json:"user_agent"`
73
+	DpReport       string     `json:"dp_report,omitempty"`
74
+	Dp             string     `json:"dp,omitempty"`
75
+	OrderName      string     `json:"order_name,omitempty"`
76
+	Result         int        `json:"result"`
77
+	Msg            string     `json:"msg"`
77
 }
78
 }
78
 
79
 
79
 func getAdsReqUrl(dsp *utils.DspParam) string {
80
 func getAdsReqUrl(dsp *utils.DspParam) string {
@@ -114,7 +115,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
114
 	fmt.Printf("req url: %s\n", reqUrl)
115
 	fmt.Printf("req url: %s\n", reqUrl)
115
 	req, err := http.NewRequest("GET", reqUrl, nil)
116
 	req, err := http.NewRequest("GET", reqUrl, nil)
116
 	if err != nil {
117
 	if err != nil {
117
-		return nil,  err
118
+		return nil, err
118
 	}
119
 	}
119
 
120
 
120
 	req.Header.Set(",authority", "m.video.xiaomi.com")
121
 	req.Header.Set(",authority", "m.video.xiaomi.com")
@@ -137,7 +138,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
137
 	body, err := ioutil.ReadAll(resp.Body)
138
 	body, err := ioutil.ReadAll(resp.Body)
138
 	fmt.Printf("rsp body: %s\n", body)
139
 	fmt.Printf("rsp body: %s\n", body)
139
 	if err != nil {
140
 	if err != nil {
140
-		return nil,  err
141
+		return nil, err
141
 	}
142
 	}
142
 	rsp := XiaoMiAdInfoRsp{}
143
 	rsp := XiaoMiAdInfoRsp{}
143
 	err = json.Unmarshal(body, &rsp)
144
 	err = json.Unmarshal(body, &rsp)
@@ -187,9 +188,9 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
187
 
188
 
188
 	for _, target := range rsp.Data[0].TargetAddition {
189
 	for _, target := range rsp.Data[0].TargetAddition {
189
 		target := html.UnescapeString(target)
190
 		target := html.UnescapeString(target)
190
-		targetParseUrl, _ := url.Parse(target)
191
+		targetParseUrl, err := url.Parse(target)
191
 		if err != nil {
192
 		if err != nil {
192
-			fmt.Printf("parse url failed, url: %s, err: %s", target, err)
193
+			log.Errorf("parse url failed, url: %s, err: %s", target, err)
193
 			continue
194
 			continue
194
 		}
195
 		}
195
 
196
 
@@ -266,7 +267,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
266
 	fmt.Printf("goto urls: %+v\nshow urls: %+v\nclick_urls: %+v\nclose urls: %+v\nvideo finish urls: %+v\nimagurls: %+v\nvideo urls:%+v\n",
267
 	fmt.Printf("goto urls: %+v\nshow urls: %+v\nclick_urls: %+v\nclose urls: %+v\nvideo finish urls: %+v\nimagurls: %+v\nvideo urls:%+v\n",
267
 		gotoUrls, showUrls, clickUrls, closeUrls, videoFinishUrls, imageUrls, videoUrls)
268
 		gotoUrls, showUrls, clickUrls, closeUrls, videoFinishUrls, imageUrls, videoUrls)
268
 
269
 
269
-	adsData, err := CombineLastAdsInfos(dsp, advertiser, gotoUrls, showUrls, clickUrls, closeUrls, videoFinishUrls, videoTimerUrls, imageUrls, videoUrls)
270
+	adsData, err := CombineLastAdsInfos(dsp, advertiser, gotoUrls, showUrls, clickUrls, closeUrls, videoFinishUrls, videoTimerUrls, videoUrls)
270
 	if err != nil {
271
 	if err != nil {
271
 		return nil, err
272
 		return nil, err
272
 	}
273
 	}
@@ -292,15 +293,6 @@ func getActionsConf(advertiser string) []string {
292
 	return actions
293
 	return actions
293
 }
294
 }
294
 
295
 
295
-func getDurationConf(advertiser string) int {
296
-	svrConf := adslib.GetConf()
297
-	duration, ok := svrConf.AdsDuration[advertiser]
298
-	if !ok {
299
-		return 0
300
-	}
301
-	return duration
302
-}
303
-
304
 func getCombinationActionsConf(advertiser string) []adslib.CombinationActionsConf {
296
 func getCombinationActionsConf(advertiser string) []adslib.CombinationActionsConf {
305
 	svrConf := adslib.GetConf()
297
 	svrConf := adslib.GetConf()
306
 	combinationActions, ok := svrConf.CombinationActions[advertiser]
298
 	combinationActions, ok := svrConf.CombinationActions[advertiser]
@@ -313,7 +305,7 @@ func getCombinationActionsConf(advertiser string) []adslib.CombinationActionsCon
313
 // 组装最后的广告信息
305
 // 组装最后的广告信息
314
 func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []string, showUrls []string,
306
 func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []string, showUrls []string,
315
 	clickUrls []string, closeUrls []string, videoFinishUrls []string,
307
 	clickUrls []string, closeUrls []string, videoFinishUrls []string,
316
-	videoTimerUrls []string, imageUrls []string, videoUrls []string) (*AdData, error) {
308
+	videoTimerUrls []string, videoUrls []string) (*AdData, error) {
317
 
309
 
318
 	// 判断是不是关掉所有Action
310
 	// 判断是不是关掉所有Action
319
 	actions := getActionsConf(advertiser)
311
 	actions := getActionsConf(advertiser)
@@ -323,10 +315,11 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
323
 
315
 
324
 	clickChannelFlag, err := redis_data.GetChannelFlag(dsp.ReqSource, "ads_click")
316
 	clickChannelFlag, err := redis_data.GetChannelFlag(dsp.ReqSource, "ads_click")
325
 	if err != nil {
317
 	if err != nil {
318
+		log.Errorf("get ads_click channel flag failed: %s", err)
326
 		return nil, err
319
 		return nil, err
327
 	}
320
 	}
328
 
321
 
329
-	fmt.Printf("click channel flag: %+v\n", clickChannelFlag)
322
+	log.Tracef("click channel flag: %+v\n", clickChannelFlag)
330
 
323
 
331
 	clickRandom := rand.Intn(100)
324
 	clickRandom := rand.Intn(100)
332
 	needClick := false
325
 	needClick := false
@@ -468,6 +461,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
468
 
461
 
469
 		canReport, err := redis_data.GetDeviceIpReport(dsp.Imei, dsp.Ip)
462
 		canReport, err := redis_data.GetDeviceIpReport(dsp.Imei, dsp.Ip)
470
 		if err != nil {
463
 		if err != nil {
464
+			log.Errorf("get device ip report failed: %s", err)
471
 			return nil, err
465
 			return nil, err
472
 		}
466
 		}
473
 
467
 
@@ -481,8 +475,8 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
481
 			}
475
 			}
482
 
476
 
483
 			conf := adslib.GetConf()
477
 			conf := adslib.GetConf()
484
-			url := strings.ReplaceAll(conf.HostMiao, "__IMEI__", md5Imei)
485
-			adData.Urls = append(adData.Urls, url)
478
+			adDataUrl := strings.ReplaceAll(conf.HostMiao, "__IMEI__", md5Imei)
479
+			adData.Urls = append(adData.Urls, adDataUrl)
486
 			redis_data.SetDeviceIpReport(dsp.Imei, dsp.Ip)
480
 			redis_data.SetDeviceIpReport(dsp.Imei, dsp.Ip)
487
 		}
481
 		}
488
 		rspAdDatas = append(rspAdDatas, adData)
482
 		rspAdDatas = append(rspAdDatas, adData)
@@ -511,7 +505,6 @@ func genAdsAction(urls []string, advertiser string,
511
 	}
505
 	}
512
 
506
 
513
 	flowControlConf := redis_data.GetFlowPercentDuration(advertiser, action)
507
 	flowControlConf := redis_data.GetFlowPercentDuration(advertiser, action)
514
-	fmt.Printf("%+v\n", flowControlConf)
515
 
508
 
516
 	flowPercent := 0
509
 	flowPercent := 0
517
 	duration := 0
510
 	duration := 0
@@ -523,11 +516,11 @@ func genAdsAction(urls []string, advertiser string,
523
 	lastUrls := make([]string, 0, 20)
516
 	lastUrls := make([]string, 0, 20)
524
 	if !needControl || allSendNum == 0 || int(
517
 	if !needControl || allSendNum == 0 || int(
525
 		float32(allShowNum)/float32(allSendNum)*100) < flowPercent {
518
 		float32(allShowNum)/float32(allSendNum)*100) < flowPercent {
526
-		reportUrl := getReportUrl(action, advertiser, dsp)
519
+		reportUrl := getReportUrl(action, dsp)
527
 		lastUrls = append(urls, reportUrl)
520
 		lastUrls = append(urls, reportUrl)
528
 	}
521
 	}
529
 
522
 
530
-	fmt.Printf("%+v\n", lastUrls)
523
+	log.Tracef("action: %s, all send: %d,  all show: %d, control: +%v %+v %t\n", action, allSendNum, allShowNum, flowControlConf, lastUrls, needControl)
531
 
524
 
532
 	if len(lastUrls) == 0 {
525
 	if len(lastUrls) == 0 {
533
 		duration = 0
526
 		duration = 0
@@ -544,9 +537,9 @@ func genAdsAction(urls []string, advertiser string,
544
 }
537
 }
545
 
538
 
546
 // 组装上报的url
539
 // 组装上报的url
547
-func getReportUrl(action string, advertiser string, dsp *utils.DspParam) string {
540
+func getReportUrl(action string, dsp *utils.DspParam) string {
548
 	urlHost := adslib.GetConf().HostIos
541
 	urlHost := adslib.GetConf().HostIos
549
-	url := fmt.Sprintf("%s?action=%s&advertiser=video&req_source=%s&brand=%s&city_code=%d&request_id=%s&spefial_flag=%d",
542
+	reportUrl := fmt.Sprintf("%s?action=%s&advertiser=video&req_source=%s&brand=%s&city_code=%d&request_id=%s&spefial_flag=%d",
550
 		urlHost, action, dsp.ReqSource, dsp.Brand, dsp.DspCityCode, dsp.RequestId, dsp.SendPhoneType)
543
 		urlHost, action, dsp.ReqSource, dsp.Brand, dsp.DspCityCode, dsp.RequestId, dsp.SendPhoneType)
551
-	return url
544
+	return reportUrl
552
 }
545
 }

File diff suppressed because it is too large
+ 9 - 10
adslib/addata/xiaomi_test.go


+ 21 - 18
adslib/device/device.go

@@ -4,6 +4,7 @@ import (
4
 	"encoding/json"
4
 	"encoding/json"
5
 	"fmt"
5
 	"fmt"
6
 	"github.com/gomodule/redigo/redis"
6
 	"github.com/gomodule/redigo/redis"
7
+	log "github.com/sirupsen/logrus"
7
 	"math/rand"
8
 	"math/rand"
8
 	"miads/adslib/ads_redis"
9
 	"miads/adslib/ads_redis"
9
 	"miads/adslib/utils"
10
 	"miads/adslib/utils"
@@ -12,7 +13,6 @@ import (
12
 	"time"
13
 	"time"
13
 )
14
 )
14
 
15
 
15
-
16
 type DeviceConf struct {
16
 type DeviceConf struct {
17
 	Imei       string `json:"imei"`
17
 	Imei       string `json:"imei"`
18
 	OriginImei string `json:"origin_imei"`
18
 	OriginImei string `json:"origin_imei"`
@@ -20,7 +20,7 @@ type DeviceConf struct {
20
 }
20
 }
21
 
21
 
22
 func SetAdsTagLog(adv string, reqSource string, key string, cityCode int) {
22
 func SetAdsTagLog(adv string, reqSource string, key string, cityCode int) {
23
-	k := fmt.Sprintf("%s___%s___%s___%d",adv,reqSource,key,cityCode)
23
+	k := fmt.Sprintf("%s___%s___%s___%d", adv, reqSource, key, cityCode)
24
 	setTagLog(k)
24
 	setTagLog(k)
25
 }
25
 }
26
 
26
 
@@ -29,9 +29,9 @@ func setTagLog(key string) {
29
 	defer conn.Close()
29
 	defer conn.Close()
30
 
30
 
31
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
31
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
32
-	k := fmt.Sprintf("{%s}___{%d}",key, dateInt)
33
-	conn.Do("INCR", k)
34
-	conn.Do("SADD", "fresh_all_keys", k)
32
+	k := fmt.Sprintf("{%s}___{%d}", key, dateInt)
33
+	_, _ = conn.Do("INCR", k)
34
+	_, _ = conn.Do("SADD", "fresh_all_keys", k)
35
 }
35
 }
36
 
36
 
37
 // 存储ip上一次请求时间
37
 // 存储ip上一次请求时间
@@ -41,7 +41,7 @@ func SetIpReqTime(ip string, reqTime int64) {
41
 
41
 
42
 	ipKey := strings.ReplaceAll(ip, ".", "")
42
 	ipKey := strings.ReplaceAll(ip, ".", "")
43
 	redisKey := "adip_" + ipKey
43
 	redisKey := "adip_" + ipKey
44
-	conn.Do("SET", redisKey, reqTime)
44
+	_, _ = conn.Do("SET", redisKey, reqTime)
45
 }
45
 }
46
 
46
 
47
 // 获取这个ip最近一次请求的时间
47
 // 获取这个ip最近一次请求的时间
@@ -59,7 +59,7 @@ func GetIpReqTime(ip string) (int64, error) {
59
 		return 0, err
59
 		return 0, err
60
 	}
60
 	}
61
 	lastReqTime, _ := redis.Int64(rsp, err)
61
 	lastReqTime, _ := redis.Int64(rsp, err)
62
-	return lastReqTime,nil
62
+	return lastReqTime, nil
63
 }
63
 }
64
 
64
 
65
 func SetMiDeviceConf(key string, d DeviceConf) error {
65
 func SetMiDeviceConf(key string, d DeviceConf) error {
@@ -70,19 +70,19 @@ func SetMiDeviceConf(key string, d DeviceConf) error {
70
 	if err != nil {
70
 	if err != nil {
71
 		return err
71
 		return err
72
 	}
72
 	}
73
-	conn.Do("set", key, deviceConfBytes,86400)
73
+	_, _ = conn.Do("set", key, deviceConfBytes, 86400)
74
 	return nil
74
 	return nil
75
 }
75
 }
76
 
76
 
77
 // 获取设备
77
 // 获取设备
78
-func GetMiDeviceConf(ip string , randNum int, specialDeviceNum int) (*DeviceConf, string, error){
78
+func GetMiDeviceConf(ip string, randNum int, specialDeviceNum int) (*DeviceConf, string, error) {
79
 	conn := ads_redis.RedisConn.Get()
79
 	conn := ads_redis.RedisConn.Get()
80
 	defer conn.Close()
80
 	defer conn.Close()
81
 
81
 
82
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
82
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
83
 	rd := 0
83
 	rd := 0
84
-	if specialDeviceNum==0 {
85
-		rd = rand.Intn(randNum - 1) + 1
84
+	if specialDeviceNum == 0 {
85
+		rd = rand.Intn(randNum-1) + 1
86
 	} else {
86
 	} else {
87
 		rd = specialDeviceNum
87
 		rd = specialDeviceNum
88
 	}
88
 	}
@@ -117,14 +117,14 @@ func SetDailyFakeDeviceConfByCityCode(cityCode int, d DeviceConf, dateInt int) e
117
 	if err != nil {
117
 	if err != nil {
118
 		return err
118
 		return err
119
 	}
119
 	}
120
-	conn.Do("SADD", redisKey, deviceConfBytes)
121
-	conn.Do("expire", redisKey, 129600)
120
+	_, _ = conn.Do("SADD", redisKey, deviceConfBytes)
121
+	_, _ = conn.Do("expire", redisKey, 129600)
122
 
122
 
123
 	return nil
123
 	return nil
124
 }
124
 }
125
 
125
 
126
 // 获取每天的设备imei
126
 // 获取每天的设备imei
127
-func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error){
127
+func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error) {
128
 	conn := ads_redis.RedisConn.Get()
128
 	conn := ads_redis.RedisConn.Get()
129
 	defer conn.Close()
129
 	defer conn.Close()
130
 
130
 
@@ -166,8 +166,11 @@ func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error){
166
 
166
 
167
 	if validDeviceConf != nil {
167
 	if validDeviceConf != nil {
168
 		// 用过的device_id放入明天的key中
168
 		// 用过的device_id放入明天的key中
169
-		tomorryDateInt, _ :=  strconv.Atoi(time.Now().AddDate(0, 0, 1).Format("20060102"))
170
-		SetDailyFakeDeviceConfByCityCode(cityCode, *validDeviceConf, tomorryDateInt)
169
+		tomorrowDateInt, _ := strconv.Atoi(time.Now().AddDate(0, 0, 1).Format("20060102"))
170
+		err := SetDailyFakeDeviceConfByCityCode(cityCode, *validDeviceConf, tomorrowDateInt)
171
+		if err != nil {
172
+			log.Errorf("set daily fake device conf by city code failed: %s", err)
173
+		}
171
 	}
174
 	}
172
 
175
 
173
 	// 获取剩余的量
176
 	// 获取剩余的量
@@ -189,7 +192,7 @@ func CheckIsBlackImei(imei string, needMd5 bool) (bool, error) {
189
 	}
192
 	}
190
 
193
 
191
 	redisKey := "ads_black_device_" + checkImei[0:2]
194
 	redisKey := "ads_black_device_" + checkImei[0:2]
192
-	isBlackImei, err := redis.Bool(conn.Do("sismember", redisKey, checkImei))
195
+	isBlackImei, err := redis.Bool(conn.Do("SISMEMBER", redisKey, checkImei))
193
 	if err != nil {
196
 	if err != nil {
194
 		return false, err
197
 		return false, err
195
 	}
198
 	}
@@ -203,5 +206,5 @@ func AddCityCodeBlackImei(cityCode int, imei string) {
203
 	defer conn.Close()
206
 	defer conn.Close()
204
 
207
 
205
 	redisKey := fmt.Sprintf("blic_%d", cityCode)
208
 	redisKey := fmt.Sprintf("blic_%d", cityCode)
206
-	conn.Do("sadd", redisKey, imei)
209
+	_, _ = conn.Do("sadd", redisKey, imei)
207
 }
210
 }

+ 10 - 24
adslib/encrypt/aes.go

@@ -4,10 +4,7 @@ import (
4
 	"bytes"
4
 	"bytes"
5
 	"crypto/aes"
5
 	"crypto/aes"
6
 	"crypto/cipher"
6
 	"crypto/cipher"
7
-	"crypto/rand"
8
-	"encoding/base64"
9
 	"encoding/hex"
7
 	"encoding/hex"
10
-	"io"
11
 )
8
 )
12
 
9
 
13
 /*CBC加密 按照golang标准库的例子代码
10
 /*CBC加密 按照golang标准库的例子代码
@@ -17,19 +14,13 @@ import (
17
 //使用PKCS7进行填充,IOS也是7
14
 //使用PKCS7进行填充,IOS也是7
18
 func pkcs7Padding(ciphertext []byte, blockSize int) []byte {
15
 func pkcs7Padding(ciphertext []byte, blockSize int) []byte {
19
 	padding := blockSize - len(ciphertext)%blockSize
16
 	padding := blockSize - len(ciphertext)%blockSize
20
-	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
17
+	padtext := bytes.Repeat([]byte{byte(0)}, padding)
21
 	return append(ciphertext, padtext...)
18
 	return append(ciphertext, padtext...)
22
 }
19
 }
23
 
20
 
24
-func pkcs7UnPadding(origData []byte) []byte {
25
-	length := len(origData)
26
-	unpadding := int(origData[length-1])
27
-	return origData[:(length - unpadding)]
28
-}
29
-
30
-func ZeroPadding(ciphertext []byte, blockSize int) []byte {
21
+func pkcs7UnPadding(ciphertext []byte, blockSize int) []byte {
31
 	padding := blockSize - len(ciphertext)%blockSize
22
 	padding := blockSize - len(ciphertext)%blockSize
32
-	padtext := bytes.Repeat([]byte{0}, padding)//用0去填充
23
+	padtext := bytes.Repeat([]byte{0}, padding) //用0去填充
33
 	return append(ciphertext, padtext...)
24
 	return append(ciphertext, padtext...)
34
 }
25
 }
35
 
26
 
@@ -44,17 +35,12 @@ func AesCBCEncrypt(rawData, key []byte) ([]byte, error) {
44
 	blockSize := block.BlockSize()
35
 	blockSize := block.BlockSize()
45
 
36
 
46
 	rawData = pkcs7Padding(rawData, blockSize)
37
 	rawData = pkcs7Padding(rawData, blockSize)
47
-	//初始向量IV必须是唯一,但不需要保密
48
-	cipherText := make([]byte, blockSize+len(rawData))
49
-	//block大小 16
50
-	iv := cipherText[:blockSize]
51
-	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
52
-		panic(err)
53
-	}
38
+
39
+	cipherText := make([]byte, len(rawData))
54
 
40
 
55
 	//block大小和初始向量大小一定要一致
41
 	//block大小和初始向量大小一定要一致
56
-	mode := cipher.NewCBCEncrypter(block, iv)
57
-	mode.CryptBlocks(cipherText[blockSize:], rawData)
42
+	mode := cipher.NewCBCEncrypter(block, key)
43
+	mode.CryptBlocks(cipherText, rawData)
58
 
44
 
59
 	return cipherText, nil
45
 	return cipherText, nil
60
 }
46
 }
@@ -81,7 +67,7 @@ func AesCBCDecrypt(encryptData, key []byte) ([]byte, error) {
81
 	// CryptBlocks can work in-place if the two arguments are the same.
67
 	// CryptBlocks can work in-place if the two arguments are the same.
82
 	mode.CryptBlocks(encryptData, encryptData)
68
 	mode.CryptBlocks(encryptData, encryptData)
83
 	//解填充
69
 	//解填充
84
-	encryptData = ZeroPadding(encryptData, blockSize)
70
+	encryptData = pkcs7UnPadding(encryptData, blockSize)
85
 	return encryptData, nil
71
 	return encryptData, nil
86
 }
72
 }
87
 
73
 
@@ -90,7 +76,8 @@ func Encrypt(rawData, key []byte) (string, error) {
90
 	if err != nil {
76
 	if err != nil {
91
 		return "", err
77
 		return "", err
92
 	}
78
 	}
93
-	return base64.StdEncoding.EncodeToString(data), nil
79
+	encryptData := hex.EncodeToString(data)
80
+	return encryptData, nil
94
 }
81
 }
95
 
82
 
96
 func Decrypt(rawData string, key []byte) (string, error) {
83
 func Decrypt(rawData string, key []byte) (string, error) {
@@ -104,4 +91,3 @@ func Decrypt(rawData string, key []byte) (string, error) {
104
 	}
91
 	}
105
 	return string(dnData), nil
92
 	return string(dnData), nil
106
 }
93
 }
107
-

+ 11 - 8
adslib/redis_data/order.go

@@ -4,6 +4,7 @@ import (
4
 	"encoding/base64"
4
 	"encoding/base64"
5
 	"encoding/json"
5
 	"encoding/json"
6
 	"github.com/gomodule/redigo/redis"
6
 	"github.com/gomodule/redigo/redis"
7
+	log "github.com/sirupsen/logrus"
7
 	"miads/adslib/ads_redis"
8
 	"miads/adslib/ads_redis"
8
 	"miads/adslib/graylog"
9
 	"miads/adslib/graylog"
9
 	"miads/adslib/utils"
10
 	"miads/adslib/utils"
@@ -85,10 +86,12 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
85
 		return []AdOrderInfo{}, err
86
 		return []AdOrderInfo{}, err
86
 	}
87
 	}
87
 
88
 
89
+	log.Tracef("order infos: %s", orderIds)
88
 	orders := make([]AdOrderInfo, 0, 50)
90
 	orders := make([]AdOrderInfo, 0, 50)
89
 	for _, id := range orderIds {
91
 	for _, id := range orderIds {
90
 		order, err := getOrderInfo(id)
92
 		order, err := getOrderInfo(id)
91
 		if err != nil {
93
 		if err != nil {
94
+			log.Warnf("no order info for: %s", id)
92
 			continue
95
 			continue
93
 		}
96
 		}
94
 
97
 
@@ -162,10 +165,10 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
162
 				Province        string
165
 				Province        string
163
 				City            string
166
 				City            string
164
 				OrderId         int64  `json:"order_id"`
167
 				OrderId         int64  `json:"order_id"`
165
-				orderProvince   string `json:"order_province"`
166
-				orderCity       string `json:"order_city"`
167
-				orderNoProvince string `json:"order_no_province"`
168
-				orderNoCity     string `json:"order_no_city"`
168
+				OrderProvince   string `json:"order_province"`
169
+				OrderCity       string `json:"order_city"`
170
+				OrderNoProvince string `json:"order_no_province"`
171
+				OrderNoCity     string `json:"order_no_city"`
169
 			}{
172
 			}{
170
 				Ip:              dsp.Ip,
173
 				Ip:              dsp.Ip,
171
 				ShortMessage:    "area_result_v2",
174
 				ShortMessage:    "area_result_v2",
@@ -173,10 +176,10 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
173
 				Province:        dsp.Province,
176
 				Province:        dsp.Province,
174
 				City:            dsp.City,
177
 				City:            dsp.City,
175
 				OrderId:         order.OrderID,
178
 				OrderId:         order.OrderID,
176
-				orderProvince:   order.Province,
177
-				orderCity:       order.City,
178
-				orderNoProvince: order.NoProvince,
179
-				orderNoCity:     order.NoCity,
179
+				OrderProvince:   order.Province,
180
+				OrderCity:       order.City,
181
+				OrderNoProvince: order.NoProvince,
182
+				OrderNoCity:     order.NoCity,
180
 			}
183
 			}
181
 			graylog.Log(grayLogData)
184
 			graylog.Log(grayLogData)
182
 		}
185
 		}

+ 26 - 25
adslib/redis_data/redis_data.go

@@ -4,6 +4,7 @@ import (
4
 	"encoding/json"
4
 	"encoding/json"
5
 	"fmt"
5
 	"fmt"
6
 	"github.com/gomodule/redigo/redis"
6
 	"github.com/gomodule/redigo/redis"
7
+	log "github.com/sirupsen/logrus"
7
 	"miads/adslib"
8
 	"miads/adslib"
8
 	"miads/adslib/ads_redis"
9
 	"miads/adslib/ads_redis"
9
 	"strconv"
10
 	"strconv"
@@ -11,7 +12,7 @@ import (
11
 )
12
 )
12
 
13
 
13
 type ChannelFlag struct {
14
 type ChannelFlag struct {
14
-	Weigth      int `json:"weigth""`
15
+	Weigth      int `json:"weigth"`
15
 	ChannelFlag int `json:"channel_flag"`
16
 	ChannelFlag int `json:"channel_flag"`
16
 }
17
 }
17
 
18
 
@@ -39,7 +40,7 @@ func GetChannelFlag(reqSource string, business string) (*ChannelFlag, error) {
39
 	conn := ads_redis.RedisConn.Get()
40
 	conn := ads_redis.RedisConn.Get()
40
 	defer conn.Close()
41
 	defer conn.Close()
41
 
42
 
42
-	redisKey := fmt.Sprintf("acfv2_{%s}_{%s}", reqSource, business)
43
+	redisKey := fmt.Sprintf("acfv2_%s_%s", reqSource, business)
43
 	rsp, err := conn.Do("GET", redisKey)
44
 	rsp, err := conn.Do("GET", redisKey)
44
 	if err != nil {
45
 	if err != nil {
45
 		return nil, err
46
 		return nil, err
@@ -121,7 +122,7 @@ func GetAdsFeedbackNum(advertiser string, action string, bannerid int) (int, err
121
 
122
 
122
 	redisKey := fmt.Sprintf("adsv3_%s_%s_%d", advertiser, action, bannerid)
123
 	redisKey := fmt.Sprintf("adsv3_%s_%s_%d", advertiser, action, bannerid)
123
 	if time.Now().Unix()%100 == 0 {
124
 	if time.Now().Unix()%100 == 0 {
124
-		conn.Do("DELETE", redisKey)
125
+		_, _ = conn.Do("DELETE", redisKey)
125
 	}
126
 	}
126
 
127
 
127
 	rsp, err := conn.Do("GET", redisKey)
128
 	rsp, err := conn.Do("GET", redisKey)
@@ -164,17 +165,17 @@ func SetDistributeActionNum(advertiser string, action string, bannerid int) {
164
 	redisKey := fmt.Sprintf("adsv3_%s_%s_%d", advertiser, action, bannerid)
165
 	redisKey := fmt.Sprintf("adsv3_%s_%s_%d", advertiser, action, bannerid)
165
 	curTime := int(time.Now().Unix())
166
 	curTime := int(time.Now().Unix())
166
 	if curTime%100 == 0 {
167
 	if curTime%100 == 0 {
167
-		conn.Do("delete", redisKey)
168
+		_, _ = conn.Do("delete", redisKey)
168
 	}
169
 	}
169
-	conn.Do("INCR", redisKey)
170
+	_, _ = conn.Do("INCR", redisKey)
170
 }
171
 }
171
 
172
 
172
 // 获取设备+ip上报是否可以
173
 // 获取设备+ip上报是否可以
173
-func GetDeviceIpReport(deviceid string, ip string) (bool, error) {
174
+func GetDeviceIpReport(deviceId string, ip string) (bool, error) {
174
 	conn := ads_redis.RedisConn.Get()
175
 	conn := ads_redis.RedisConn.Get()
175
 	defer conn.Close()
176
 	defer conn.Close()
176
 
177
 
177
-	redisKey := fmt.Sprintf("dim2_%s_'%s'", deviceid, ip)
178
+	redisKey := fmt.Sprintf("dim2_%s_'%s'", deviceId, ip)
178
 	rsp, err := conn.Do("GET", redisKey)
179
 	rsp, err := conn.Do("GET", redisKey)
179
 	if err != nil {
180
 	if err != nil {
180
 		return false, err
181
 		return false, err
@@ -196,11 +197,11 @@ func SetDeviceIpReport(deviceid string, ip string) {
196
 	defer conn.Close()
197
 	defer conn.Close()
197
 
198
 
198
 	redisKey := fmt.Sprintf("dim2_%s_'%s'", deviceid, ip)
199
 	redisKey := fmt.Sprintf("dim2_%s_'%s'", deviceid, ip)
199
-	conn.Do("SET", redisKey, time.Now().Unix(), 3*86400)
200
+	_, _ = conn.Do("SET", redisKey, time.Now().Unix(), 3*86400)
200
 }
201
 }
201
 
202
 
202
 // 设置总请求到广告的次数
203
 // 设置总请求到广告的次数
203
-func SetAdsRequestNum(advertiser string, bannerid int) {
204
+func SetAdsRequestNum(advertiser string, bannerId int) {
204
 	if advertiser == "" {
205
 	if advertiser == "" {
205
 		return
206
 		return
206
 	}
207
 	}
@@ -208,11 +209,11 @@ func SetAdsRequestNum(advertiser string, bannerid int) {
208
 	conn := ads_redis.RedisConn.Get()
209
 	conn := ads_redis.RedisConn.Get()
209
 	defer conn.Close()
210
 	defer conn.Close()
210
 
211
 
211
-	redisKey := fmt.Sprintf("adsv2_%s_%d", advertiser, bannerid)
212
+	redisKey := fmt.Sprintf("adsv2_%s_%d", advertiser, bannerId)
212
 	if time.Now().Unix()%100 == 0 {
213
 	if time.Now().Unix()%100 == 0 {
213
-		conn.Do("delete", redisKey)
214
+		_, _ = conn.Do("delete", redisKey)
214
 	}
215
 	}
215
-	conn.Do("incr", redisKey)
216
+	_, _ = conn.Do("incr", redisKey)
216
 }
217
 }
217
 
218
 
218
 func SetAdsRealRequestNum(advertiser string) {
219
 func SetAdsRealRequestNum(advertiser string) {
@@ -224,7 +225,7 @@ func SetAdsRealRequestNum(advertiser string) {
224
 	defer conn.Close()
225
 	defer conn.Close()
225
 
226
 
226
 	redisKey := fmt.Sprintf("adsv2_request_%s", advertiser)
227
 	redisKey := fmt.Sprintf("adsv2_request_%s", advertiser)
227
-	conn.Do("incr", redisKey)
228
+	_, _ = conn.Do("incr", redisKey)
228
 }
229
 }
229
 
230
 
230
 // 设置skip redis
231
 // 设置skip redis
@@ -233,7 +234,7 @@ func SetSkipInfo(md5Skip string, skipUrl string) {
233
 	defer conn.Close()
234
 	defer conn.Close()
234
 
235
 
235
 	redisKey := "su_" + md5Skip
236
 	redisKey := "su_" + md5Skip
236
-	conn.Do("set", redisKey, skipUrl, 300)
237
+	_, _ = conn.Do("set", redisKey, skipUrl, 300)
237
 }
238
 }
238
 
239
 
239
 // 通过advertiser获取最小的script_order
240
 // 通过advertiser获取最小的script_order
@@ -261,7 +262,7 @@ func SetReqSourceView(adv string, reqSource string, source string) {
261
 
262
 
262
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
263
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
263
 	key := fmt.Sprintf("view3_%s_%s_%d_%s", adv, reqSource, dateInt, source)
264
 	key := fmt.Sprintf("view3_%s_%s_%d_%s", adv, reqSource, dateInt, source)
264
-	conn.Do("incr", key)
265
+	_, _ = conn.Do("incr", key)
265
 }
266
 }
266
 
267
 
267
 // 获取剩余总投放量
268
 // 获取剩余总投放量
@@ -327,6 +328,7 @@ func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTi
327
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
328
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
328
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
329
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
329
 	rsp, err := conn.Do("GET", key)
330
 	rsp, err := conn.Do("GET", key)
331
+	log.Infof("%s %s", key, rsp)
330
 	if err != nil {
332
 	if err != nil {
331
 		return 0, err
333
 		return 0, err
332
 	}
334
 	}
@@ -362,7 +364,7 @@ func SetPlanDispatchCount(orderId int64, dispatchType string, cnt int, curTime t
362
 	defer conn.Close()
364
 	defer conn.Close()
363
 
365
 
364
 	key := fmt.Sprintf("plan_all_kpi_%d_%d%d%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), dispatchType)
366
 	key := fmt.Sprintf("plan_all_kpi_%d_%d%d%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), dispatchType)
365
-	conn.Do("SET", key, cnt, 3600*24)
367
+	_, _ = conn.Do("SET", key, cnt, 3600*24)
366
 }
368
 }
367
 
369
 
368
 // 设置订单计划投放数量
370
 // 设置订单计划投放数量
@@ -373,7 +375,7 @@ func SetOrderPlanDispatchCount(orderId int64, dispatchType string, cnt int, curT
373
 
375
 
374
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
376
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
375
 	key := fmt.Sprintf("plan_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
377
 	key := fmt.Sprintf("plan_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
376
-	conn.Do("SET", key, cnt, 3600*24)
378
+	_, _ = conn.Do("SET", key, cnt, 3600*24)
377
 }
379
 }
378
 
380
 
379
 // 获取总量每分钟要投放的量
381
 // 获取总量每分钟要投放的量
@@ -442,24 +444,23 @@ func GetIosUaImei(ip string) (string, string, error) {
442
 			return "", "", nil
444
 			return "", "", nil
443
 		}
445
 		}
444
 
446
 
445
-		conn.Do("SREM", redisKey, rsp)
447
+		_, _ = conn.Do("SREM", redisKey, rsp)
446
 
448
 
447
 		tomorrowDateInt, _ := strconv.Atoi(time.Unix(time.Now().Unix()+86400, 0).Format("20060102"))
449
 		tomorrowDateInt, _ := strconv.Atoi(time.Unix(time.Now().Unix()+86400, 0).Format("20060102"))
448
 		redisKey = fmt.Sprintf("new_ios_ua_v2_%d", tomorrowDateInt)
450
 		redisKey = fmt.Sprintf("new_ios_ua_v2_%d", tomorrowDateInt)
449
-		conn.Do("SADD", redisKey, rsp)
450
-	}
451
-
452
-	if rsp == nil {
453
-		return "", "", nil
451
+		_, _ = conn.Do("SADD", redisKey, rsp)
454
 	}
452
 	}
455
 
453
 
456
-	conn.Do("SET", iosUaImeiRedisKey, rsp, 86520)
454
+	_, _ = conn.Do("SET", iosUaImeiRedisKey, rsp, 86520)
457
 
455
 
458
 	var uaImeiInfo struct {
456
 	var uaImeiInfo struct {
459
 		Imei string
457
 		Imei string
460
 		Ua   string
458
 		Ua   string
461
 	}
459
 	}
462
 	rspBytes, _ := redis.Bytes(rsp, err)
460
 	rspBytes, _ := redis.Bytes(rsp, err)
463
-	json.Unmarshal(rspBytes, &uaImeiInfo)
461
+	err = json.Unmarshal(rspBytes, &uaImeiInfo)
462
+	if err != nil {
463
+		return "", "", err
464
+	}
464
 	return uaImeiInfo.Imei, uaImeiInfo.Ua, nil
465
 	return uaImeiInfo.Imei, uaImeiInfo.Ua, nil
465
 }
466
 }

+ 12 - 1
go.mod

@@ -4,12 +4,23 @@ go 1.12
4
 
4
 
5
 require (
5
 require (
6
 	github.com/BurntSushi/toml v0.3.1
6
 	github.com/BurntSushi/toml v0.3.1
7
-	github.com/beanstalkd/go-beanstalk v0.0.0-20200526060843-1cc502ecaf3c
7
+	github.com/agiledragon/gomonkey v2.0.1+incompatible
8
+	github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
9
+	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
8
 	github.com/gin-gonic/gin v1.6.3
10
 	github.com/gin-gonic/gin v1.6.3
9
 	github.com/gomodule/redigo v2.0.0+incompatible
11
 	github.com/gomodule/redigo v2.0.0+incompatible
10
 	github.com/jarcoal/httpmock v1.0.5
12
 	github.com/jarcoal/httpmock v1.0.5
13
+	github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
14
+	github.com/jonboulle/clockwork v0.1.0 // indirect
15
+	github.com/kr/pretty v0.2.0 // indirect
16
+	github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible
17
+	github.com/lestrrat-go/strftime v1.0.1 // indirect
18
+	github.com/lintianzhi/graylogd v0.0.0-20180503131252-dc68342f04dc // indirect
11
 	github.com/lionsoul2014/ip2region v2.1.0-release+incompatible
19
 	github.com/lionsoul2014/ip2region v2.1.0-release+incompatible
20
+	github.com/pkg/errors v0.9.1 // indirect
12
 	github.com/rafaeljusto/redigomock v2.4.0+incompatible
21
 	github.com/rafaeljusto/redigomock v2.4.0+incompatible
13
 	github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827
22
 	github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827
23
+	github.com/sirupsen/logrus v1.6.0
14
 	github.com/stretchr/testify v1.4.0
24
 	github.com/stretchr/testify v1.4.0
25
+	github.com/tebeka/strftime v0.1.4 // indirect
15
 )
26
 )

+ 40 - 2
go.sum

@@ -1,14 +1,19 @@
1
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
1
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3
-github.com/beanstalkd/go-beanstalk v0.0.0-20200526060843-1cc502ecaf3c h1:D8zSant5V63LdrIHuEoJ82Yiyo1SRXEg+REzRuZnsbk=
4
-github.com/beanstalkd/go-beanstalk v0.0.0-20200526060843-1cc502ecaf3c/go.mod h1:Q3f6RCbUHp8RHSfBiPUZBojK76rir8Rl+KINuz2/sYs=
3
+github.com/agiledragon/gomonkey v2.0.1+incompatible h1:DIQT3ZshgGz9pTwBddRSZWDutIRPx2d7UzmjzgWo9q0=
4
+github.com/agiledragon/gomonkey v2.0.1+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
5
+github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
6
+github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
5
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10
+github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJdVkTrXpu9KtoVCSo1hg7mtI7G9KU=
11
+github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw=
8
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
12
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
9
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
13
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
10
 github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
14
 github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
11
 github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
15
 github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
16
+github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
12
 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
17
 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
13
 github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
18
 github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
14
 github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
19
 github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
@@ -23,32 +28,65 @@ github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp
23
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
28
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
24
 github.com/jarcoal/httpmock v1.0.5 h1:cHtVEcTxRSX4J0je7mWPfc9BpDpqzXSJ5HbymZmyHck=
29
 github.com/jarcoal/httpmock v1.0.5 h1:cHtVEcTxRSX4J0je7mWPfc9BpDpqzXSJ5HbymZmyHck=
25
 github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
30
 github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
31
+github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
32
+github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
33
+github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
34
+github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
35
+github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
26
 github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
36
 github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
37
+github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
38
+github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
39
+github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
40
+github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
41
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
42
+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
43
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
27
 github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
44
 github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
28
 github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
45
 github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
46
+github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
47
+github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
48
+github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible h1:4mNlp+/SvALIPFpbXV3kxNJJno9iKFWGxSDE13Kl66Q=
49
+github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
50
+github.com/lestrrat-go/strftime v1.0.1 h1:o7qz5pmLzPDLyGW4lG6JvTKPUfTFXwe+vOamIYWtnVU=
51
+github.com/lestrrat-go/strftime v1.0.1/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
52
+github.com/lintianzhi/graylogd v0.0.0-20180503131252-dc68342f04dc h1:7f0qjuEBw/5vUrP2lyIUgAihl0A6H0E79kswNy6edeE=
53
+github.com/lintianzhi/graylogd v0.0.0-20180503131252-dc68342f04dc/go.mod h1:WTHfLzkGmTEe+nyJqdZhFbAWUkyI30IVS9ytgHDJj0I=
29
 github.com/lionsoul2014/ip2region v2.1.0-release+incompatible h1:FHT0RIeHl5C1G+V0mhKI+kFoBoDOPBEmF8hVhKZcmNs=
54
 github.com/lionsoul2014/ip2region v2.1.0-release+incompatible h1:FHT0RIeHl5C1G+V0mhKI+kFoBoDOPBEmF8hVhKZcmNs=
30
 github.com/lionsoul2014/ip2region v2.1.0-release+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI=
55
 github.com/lionsoul2014/ip2region v2.1.0-release+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI=
31
 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
56
 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
32
 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
57
 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
58
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
33
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
59
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
60
+github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
34
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
61
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
62
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
63
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
64
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
35
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
65
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
36
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
66
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
37
 github.com/rafaeljusto/redigomock v2.4.0+incompatible h1:d7uo5MVINMxnRr20MxbgDkmZ8QRfevjOVgEa4n0OZyY=
67
 github.com/rafaeljusto/redigomock v2.4.0+incompatible h1:d7uo5MVINMxnRr20MxbgDkmZ8QRfevjOVgEa4n0OZyY=
38
 github.com/rafaeljusto/redigomock v2.4.0+incompatible/go.mod h1:JaY6n2sDr+z2WTsXkOmNRUfDy6FN0L6Nk7x06ndm4tY=
68
 github.com/rafaeljusto/redigomock v2.4.0+incompatible/go.mod h1:JaY6n2sDr+z2WTsXkOmNRUfDy6FN0L6Nk7x06ndm4tY=
39
 github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827 h1:D2Xs0bSuqpKnUOOlK4yu6lloeOs4+oD+pjbOfsxgWu0=
69
 github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827 h1:D2Xs0bSuqpKnUOOlK4yu6lloeOs4+oD+pjbOfsxgWu0=
40
 github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827/go.mod h1:jONcYFk83vUF1lv0aERAwaFtDM9wUW4BMGmlnpLJyZY=
70
 github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827/go.mod h1:jONcYFk83vUF1lv0aERAwaFtDM9wUW4BMGmlnpLJyZY=
71
+github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
72
+github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
41
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
73
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
74
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
42
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
75
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
43
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
76
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
44
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
77
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
78
+github.com/tebeka/strftime v0.1.4 h1:e0FKSyxthD1Xk4cIixFPoyfD33u2SbjNngOaaC3ePoU=
79
+github.com/tebeka/strftime v0.1.4/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ=
45
 github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
80
 github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
46
 github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
81
 github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
47
 github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
82
 github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
48
 github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
83
 github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
84
+golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
85
+golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
49
 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
86
 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
50
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
87
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
51
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
88
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
89
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
52
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
90
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
53
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
91
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
54
 gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
92
 gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=

File diff suppressed because it is too large
+ 138 - 8
main_test.go