jiantaoli 4 yıl önce
ebeveyn
işleme
859727a6b4

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

@@ -1,11 +1,17 @@
1 1
 <component name="ProjectDictionaryState">
2 2
   <dictionary name="zhanlangpc">
3 3
     <words>
4
+      <w>adip</w>
5
+      <w>ciphertext</w>
6
+      <w>dingtou</w>
4 7
       <w>imei</w>
8
+      <w>padtext</w>
5 9
       <w>sadd</w>
10
+      <w>scard</w>
6 11
       <w>smembers</w>
7 12
       <w>srandmember</w>
8 13
       <w>srem</w>
14
+      <w>weigth</w>
9 15
     </words>
10 16
   </dictionary>
11 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 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"github.com/gin-gonic/gin"
7
+	"io"
7 8
 	"math/rand"
8 9
 	"miads/adslib"
9 10
 	"miads/adslib/addata"
@@ -16,9 +17,13 @@ import (
16 17
 	"miads/adslib/redis_data"
17 18
 	"miads/adslib/utils"
18 19
 	"net/url"
20
+	"os"
19 21
 	"strconv"
20 22
 	"strings"
21 23
 	"time"
24
+
25
+	"github.com/lestrrat-go/file-rotatelogs"
26
+	log "github.com/sirupsen/logrus"
22 27
 )
23 28
 
24 29
 type Response struct {
@@ -28,13 +33,39 @@ type Response struct {
28 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 61
 func adsHandler(c *gin.Context) {
62
+	setupLogger("log/ads.log", log.TraceLevel)
32 63
 	c.Header("Content-Type", "application/json")
33 64
 
34 65
 	request := adslib.Request{}
35 66
 	request.Parse(c)
36 67
 
37
-	fmt.Printf("%+v\n", request)
68
+	log.Printf("%+v", request)
38 69
 	advertiser := "xiaomi"
39 70
 	uaClient := request.UaClient
40 71
 	// 获取ua
@@ -111,7 +142,9 @@ func adsHandler(c *gin.Context) {
111 142
 		graylog.Log(grayLogData)
112 143
 	}
113 144
 
145
+	// 定制city code
114 146
 	cityCode, err := city.GetCityCode(ipInfo.City)
147
+	log.Infof("got city code: %d", cityCode)
115 148
 	if err != nil {
116 149
 		c.String(404, "get city code failed: %s", err)
117 150
 		return
@@ -131,11 +164,12 @@ func adsHandler(c *gin.Context) {
131 164
 		// 频率控制
132 165
 		freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
133 166
 		if err != nil {
167
+			log.Errorf("get freq control conf failed: %s", err)
134 168
 			c.String(404, "get freq control conf failed: %s", err)
135 169
 			return
136 170
 		}
137 171
 
138
-		fmt.Printf("freq control conf: %+v\n", freqControlConf)
172
+		log.Infof("freq control conf: %+v", freqControlConf)
139 173
 		hour, _ := strconv.Atoi(time.Now().Format("01"))
140 174
 		tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
141 175
 		if ok {
@@ -153,16 +187,17 @@ func adsHandler(c *gin.Context) {
153 187
 	needControl := false
154 188
 	if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
155 189
 		// 需要凭空
190
+		log.Infof("need control: %d", lastReqTime)
156 191
 		needControl = true
157 192
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
158 193
 	} else {
159 194
 		device.SetIpReqTime(ip, time.Now().Unix())
160 195
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_1", cityCode)
161 196
 	}
162
-
163 197
 	//### 检查是否是ip黑名单
164 198
 	isIpBlack, err := ads_checker.CheckBlackIp(ip)
165 199
 	if err != nil {
200
+		log.Errorf("check black ip failed: %s", err)
166 201
 		c.String(404, "check black ip failed: %s", err)
167 202
 		return
168 203
 	}
@@ -174,6 +209,7 @@ func adsHandler(c *gin.Context) {
174 209
 	// 获取渠道的黑白性
175 210
 	reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
176 211
 	if err != nil {
212
+		log.Errorf("get req channel flag failed: %s", err)
177 213
 		c.String(404, "get req channel flag failed: %s", err)
178 214
 		return
179 215
 	}
@@ -205,10 +241,12 @@ func adsHandler(c *gin.Context) {
205 241
 		randomNum := 3
206 242
 		deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
207 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 246
 			return
210 247
 		}
211 248
 		if deviceConf != nil {
249
+			log.Infof("use cache imei: %+v", deviceConf)
212 250
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
213 251
 			imei = deviceConf.Imei
214 252
 			uaClient = deviceConf.Ua
@@ -228,7 +266,8 @@ func adsHandler(c *gin.Context) {
228 266
 				fakeImei := ""
229 267
 				fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
230 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 271
 					return
233 272
 				}
234 273
 
@@ -237,7 +276,10 @@ func adsHandler(c *gin.Context) {
237 276
 				replaceUa := ""
238 277
 				if fakeDeviceConf != nil {
239 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 283
 					imei = fakeDeviceConf.Imei
242 284
 					uaClient = fakeDeviceConf.Ua
243 285
 					originImei = fakeDeviceConf.OriginImei
@@ -283,6 +325,7 @@ func adsHandler(c *gin.Context) {
283 325
 		// 解码ua_client
284 326
 		uaClient, _ = url.QueryUnescape(uaClient)
285 327
 	} else if request.IsMiDevice() {
328
+		log.Info("real mi")
286 329
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
287 330
 		userFlag = 3
288 331
 		sendPhoneType = 1
@@ -291,14 +334,18 @@ func adsHandler(c *gin.Context) {
291 334
 	// 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
292 335
 	isBlackImei, err := device.CheckIsBlackImei(imei, false)
293 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 339
 		return
296 340
 	}
297 341
 
342
+	log.Tracef("replace flag: %d", replaceFlag)
298 343
 	if isBlackImei {
299 344
 		if replaceFlag == 1 {
345
+			log.Trace("replace")
300 346
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
301 347
 		} else {
348
+			log.Trace("not replace")
302 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 386
 	dspInfo.RealMd5Imei = md5Imei
387
+	log.Infof("dsp: %+v", dspInfo)
340 388
 	//ads_item = None
341 389
 	//xiaomi_response = []
342 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 402
 	var adData *addata.AdData
353 403
 
354 404
 	// 非频率控制,设备黑名单,ip黑名单,白名单渠道,并且替换了小米设备的
355 405
 	if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
356 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 416
 	xiaomiResponseFlag := 0
361 417
 	response := Response{}
418
+	response.Msg = "ok"
362 419
 	if adData != nil && len(adData.TargetAddition) > 1 {
420
+		log.Infof("add target js order")
363 421
 		xiaomiResponseFlag = 1
364 422
 		realTarget := ""
365 423
 		if adData.Target != "" {
@@ -372,7 +430,13 @@ func adsHandler(c *gin.Context) {
372 430
 			redis_data.SetSkipInfo(md5Skip, adData.Target)
373 431
 		}
374 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 440
 		adData.UserAgent = uaClient
377 441
 
378 442
 		if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
@@ -385,21 +449,21 @@ func adsHandler(c *gin.Context) {
385 449
 			device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_GET_1", cityCode) // 广告获取成功
386 450
 		}
387 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 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 468
 		// 组装返回去的action
405 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 481
 				serverActionResponse["server_video_timer"] = 1
418 482
 			}
419 483
 		}
420
-
484
+		log.Infof("server action response: %+v", serverActionResponse)
421 485
 		// 增加跟随订单
422 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 489
 			if err != nil {
490
+				log.Errorf("combine order failed: %s", err)
425 491
 				c.String(404, "combine order failed: %s", err.Error())
426 492
 				return
427 493
 			}
494
+			log.Infof("get custom order: %+v", adData)
428 495
 		}
429 496
 
430 497
 		//# 检查最后是否有click
431
-		//last_target_addition_infos = ads_item_new.get('target_addition',[])
498
+		log.Infof("check ads item new: %+v", adData)
499
+
432 500
 		for _, targetAddition := range adData.TargetAddition {
433 501
 			if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
502
+				log.Infof("can't mix, targetAddition: %+v", targetAddition)
434 503
 				canMixFlag = 0
435 504
 				break
436 505
 			}
437 506
 		}
438 507
 
439 508
 		if request.NewAdsFlag == 0 {
440
-			//response.update(ads_item_new)
509
+			response.AdData = *adData
510
+			log.Infof("update response: +%v", response)
441 511
 		} else {
442 512
 			jsonBytes, err := json.Marshal(*adData)
443 513
 			if err != nil {
@@ -448,6 +518,8 @@ func adsHandler(c *gin.Context) {
448 518
 			response.AdsResult = encryptData
449 519
 		}
450 520
 	}
521
+
522
+	log.Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
451 523
 	if canMixFlag == 1 {
452 524
 		response.Result = 2
453 525
 		response.Msg = "no ads"
@@ -458,15 +530,17 @@ func adsHandler(c *gin.Context) {
458 530
 		// 增加打底广告
459 531
 		if (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") && !needControl && !isBlackImei {
460 532
 			shortMessage := "kong"
461
-			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 0, xiaomiResponseFlag)
533
+			// 先跑定投
534
+			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, 0, 0, xiaomiResponseFlag)
462 535
 			if err != nil {
463 536
 				c.String(404, "get custom ads info failed: %s", err.Error())
464 537
 				return
465 538
 			}
539
+			log.Infof("dingtou: %+v", customAdData)
466 540
 
467 541
 			// 定投没有就跑其他的
468 542
 			if customAdData == nil {
469
-				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, advertiser, 0, 1, xiaomiResponseFlag)
543
+				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, 0, 1, xiaomiResponseFlag)
470 544
 				if err != nil {
471 545
 					c.String(404, "get fix custom ads info failed: %s", err.Error())
472 546
 					return
@@ -478,9 +552,9 @@ func adsHandler(c *gin.Context) {
478 552
 			}
479 553
 
480 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 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 559
 				grayLogData := struct {
486 560
 					Ip           string
@@ -508,43 +582,44 @@ func adsHandler(c *gin.Context) {
508 582
 				if len(response.TargetAddition) != 0 && len(customAdData.TargetAddition) != 0 {
509 583
 					rspTargetAddition = response.TargetAddition
510 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 624
 			if customAdData != nil {
550 625
 				device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "ADS_ZIYOU_HAVE", cityCode) // 广告获取成功
@@ -552,19 +627,27 @@ func adsHandler(c *gin.Context) {
552 627
 					response.Result = 0
553 628
 					response.Msg = "ok"
554 629
 
630
+					log.Infof("rsp1: %+v", customAdData)
555 631
 					jsonBytes, err := json.Marshal(customAdData)
556 632
 					if err != nil {
557 633
 						c.String(404, "marsha custom addata failed: %s", err.Error())
558 634
 						return
559 635
 					}
636
+					log.Infof("rsp1: %s", jsonBytes)
560 637
 					encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
561 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 644
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
563 645
 					rspBytes, err := json.Marshal(response)
564 646
 					if err != nil {
565 647
 						c.String(404, "marshal Response failed: %s", err.Error())
566 648
 						return
567 649
 					}
650
+					log.Infof("rsp1: %s", rspBytes)
568 651
 					c.String(200, string(rspBytes))
569 652
 					return
570 653
 				} else {
@@ -593,5 +676,6 @@ func adsHandler(c *gin.Context) {
593 676
 		graylog.ReportGrayLog(request, dspInfo, 0, 0)
594 677
 	}
595 678
 	device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
679
+	log.Infof("rsp3: %s", rspBytes)
596 680
 	c.String(200, string(rspBytes))
597 681
 }

+ 28 - 14
adslib/addata/custom.go

@@ -2,6 +2,7 @@ package addata
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	log "github.com/sirupsen/logrus"
5 6
 	"math/rand"
6 7
 	"miads/adslib"
7 8
 	"miads/adslib/redis_data"
@@ -11,8 +12,8 @@ import (
11 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 17
 	if err != nil {
17 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 53
 	orders, err := redis_data.GetOrderInfos(dsp, fixFlag)
53 54
 	if err != nil {
@@ -127,31 +128,33 @@ func getNeedDispatchCount(adData *redis_data.AdOrderInfo) (int, error) {
127 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 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 138
 	if err != nil {
138 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 143
 	needDispatchCount := beginRemainDispatchCount - endRemainDispatchCnt
143 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 149
 	if err != nil {
150
+		log.Errorf("get one ads failed: %s", err)
149 151
 		return nil, err
150 152
 	}
151 153
 	if order == nil {
152 154
 		return nil, nil
153 155
 	}
154 156
 
157
+	log.Infof("begin got custom ad info, xiaomi has flag: %d", xiaomiHasFlag)
155 158
 	if xiaomiHasFlag == 1 {
156 159
 		if strings.Index(order.Title, "_ios") > 0 {
157 160
 			return nil, nil
@@ -176,9 +179,9 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
176 179
 		return nil, err
177 180
 	}
178 181
 
179
-	fmt.Sprintf("finish show cnt: %d\n", finishShowCnt)
180 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 186
 	rate := float32(order.ShowKpi) / float32(needDispatchCnt)
184 187
 
@@ -192,6 +195,8 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
192 195
 	if err != nil {
193 196
 		return nil, err
194 197
 	}
198
+	log.Infof("line value: %d, rate: %f", lineValue, rate)
199
+
195 200
 	// 当前分钟需要放出去的数量
196 201
 	curMinuteNeedDispatchCnt := int(float32(lineValue) * rate)
197 202
 	if curMinuteNeedDispatchCnt < 1 {
@@ -200,8 +205,11 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
200 205
 
201 206
 	redis_data.SetOrderPlanDispatchCount(order.OrderID, "show", curMinuteNeedDispatchCnt, curTime)
202 207
 
208
+	log.Infof("tt thirds: %+v", order)
203 209
 	// 获取当前分钟已经完成的下发
204 210
 	curMinuteFinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
211
+
212
+	log.Infof("o value: %d, w value: %d", curMinuteFinishedDispatchCnt, curMinuteNeedDispatchCnt)
205 213
 	if curMinuteFinishedDispatchCnt < curMinuteNeedDispatchCnt {
206 214
 		data := AdData{
207 215
 			Duration:  5,
@@ -227,6 +235,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
227 235
 		if strings.Index(order.Title, "_ios") != -1 {
228 236
 			iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
229 237
 			if err != nil {
238
+				log.Errorf("get ios ua imei failed: %s", err)
230 239
 				return nil, err
231 240
 			}
232 241
 			if iosUa != "" {
@@ -261,6 +270,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
261 270
 			if r < 40 && xiaomiHasFlag == 0 {
262 271
 				iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
263 272
 				if err != nil {
273
+					log.Errorf("get ios ua imei failed: %s", err)
264 274
 					return nil, err
265 275
 				}
266 276
 				if iosUa != "" {
@@ -310,19 +320,23 @@ func GetCustomAdsInfos(dsp *utils.DspParam, advertiser string, orderType int, fi
310 320
 
311 321
 		r := rand.Intn(1000)
312 322
 		clickRate := int(float32(order.ClickKpi) / float32(order.ShowKpi) * 1000)
323
+		log.Infof("rand: %d, rate: %d", r, clickRate)
313 324
 		if r < clickRate {
314 325
 			//下发点击
315 326
 			addi = genMonitorAction("CLICK", order.Title, dsp.ReqSource, clickUrl)
316 327
 			data.TargetAddition = append(data.TargetAddition, *addi)
317 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 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 336
 			redis_data.SetSkipInfo(md5Skip, targetUrl)
323 337
 			data.Target = realTarget
324
-			return &data, nil
325 338
 		}
339
+		return &data, nil
326 340
 	}
327 341
 
328 342
 	return nil, nil
@@ -345,7 +359,7 @@ func genMonitorAction(action string, title string, reqSource string, url string)
345 359
 	}
346 360
 	urlHost := adslib.GetConf().HostIos
347 361
 	actionUrl := fmt.Sprintf("%s?action=%s&advertiser=%s&req_source=%s",
348
-		urlHost, action, reqSource, title)
362
+		urlHost, action, title, reqSource)
349 363
 	adAction.Urls = append(adAction.Urls, actionUrl)
350 364
 	return &adAction
351 365
 }

+ 28 - 35
adslib/addata/xiaomi.go

@@ -3,6 +3,7 @@ package addata
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6
+	log "github.com/sirupsen/logrus"
6 7
 	"html"
7 8
 	"io/ioutil"
8 9
 	"math/rand"
@@ -63,17 +64,17 @@ type AdInfo struct {
63 64
 
64 65
 type AdData struct {
65 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 80
 func getAdsReqUrl(dsp *utils.DspParam) string {
@@ -114,7 +115,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
114 115
 	fmt.Printf("req url: %s\n", reqUrl)
115 116
 	req, err := http.NewRequest("GET", reqUrl, nil)
116 117
 	if err != nil {
117
-		return nil,  err
118
+		return nil, err
118 119
 	}
119 120
 
120 121
 	req.Header.Set(",authority", "m.video.xiaomi.com")
@@ -137,7 +138,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
137 138
 	body, err := ioutil.ReadAll(resp.Body)
138 139
 	fmt.Printf("rsp body: %s\n", body)
139 140
 	if err != nil {
140
-		return nil,  err
141
+		return nil, err
141 142
 	}
142 143
 	rsp := XiaoMiAdInfoRsp{}
143 144
 	err = json.Unmarshal(body, &rsp)
@@ -187,9 +188,9 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
187 188
 
188 189
 	for _, target := range rsp.Data[0].TargetAddition {
189 190
 		target := html.UnescapeString(target)
190
-		targetParseUrl, _ := url.Parse(target)
191
+		targetParseUrl, err := url.Parse(target)
191 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 194
 			continue
194 195
 		}
195 196
 
@@ -266,7 +267,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
266 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 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 271
 	if err != nil {
271 272
 		return nil, err
272 273
 	}
@@ -292,15 +293,6 @@ func getActionsConf(advertiser string) []string {
292 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 296
 func getCombinationActionsConf(advertiser string) []adslib.CombinationActionsConf {
305 297
 	svrConf := adslib.GetConf()
306 298
 	combinationActions, ok := svrConf.CombinationActions[advertiser]
@@ -313,7 +305,7 @@ func getCombinationActionsConf(advertiser string) []adslib.CombinationActionsCon
313 305
 // 组装最后的广告信息
314 306
 func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []string, showUrls []string,
315 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 310
 	// 判断是不是关掉所有Action
319 311
 	actions := getActionsConf(advertiser)
@@ -323,10 +315,11 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
323 315
 
324 316
 	clickChannelFlag, err := redis_data.GetChannelFlag(dsp.ReqSource, "ads_click")
325 317
 	if err != nil {
318
+		log.Errorf("get ads_click channel flag failed: %s", err)
326 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 324
 	clickRandom := rand.Intn(100)
332 325
 	needClick := false
@@ -468,6 +461,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
468 461
 
469 462
 		canReport, err := redis_data.GetDeviceIpReport(dsp.Imei, dsp.Ip)
470 463
 		if err != nil {
464
+			log.Errorf("get device ip report failed: %s", err)
471 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 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 480
 			redis_data.SetDeviceIpReport(dsp.Imei, dsp.Ip)
487 481
 		}
488 482
 		rspAdDatas = append(rspAdDatas, adData)
@@ -511,7 +505,6 @@ func genAdsAction(urls []string, advertiser string,
511 505
 	}
512 506
 
513 507
 	flowControlConf := redis_data.GetFlowPercentDuration(advertiser, action)
514
-	fmt.Printf("%+v\n", flowControlConf)
515 508
 
516 509
 	flowPercent := 0
517 510
 	duration := 0
@@ -523,11 +516,11 @@ func genAdsAction(urls []string, advertiser string,
523 516
 	lastUrls := make([]string, 0, 20)
524 517
 	if !needControl || allSendNum == 0 || int(
525 518
 		float32(allShowNum)/float32(allSendNum)*100) < flowPercent {
526
-		reportUrl := getReportUrl(action, advertiser, dsp)
519
+		reportUrl := getReportUrl(action, dsp)
527 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 525
 	if len(lastUrls) == 0 {
533 526
 		duration = 0
@@ -544,9 +537,9 @@ func genAdsAction(urls []string, advertiser string,
544 537
 }
545 538
 
546 539
 // 组装上报的url
547
-func getReportUrl(action string, advertiser string, dsp *utils.DspParam) string {
540
+func getReportUrl(action string, dsp *utils.DspParam) string {
548 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 543
 		urlHost, action, dsp.ReqSource, dsp.Brand, dsp.DspCityCode, dsp.RequestId, dsp.SendPhoneType)
551
-	return url
544
+	return reportUrl
552 545
 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 9 - 10
adslib/addata/xiaomi_test.go


+ 21 - 18
adslib/device/device.go

@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"github.com/gomodule/redigo/redis"
7
+	log "github.com/sirupsen/logrus"
7 8
 	"math/rand"
8 9
 	"miads/adslib/ads_redis"
9 10
 	"miads/adslib/utils"
@@ -12,7 +13,6 @@ import (
12 13
 	"time"
13 14
 )
14 15
 
15
-
16 16
 type DeviceConf struct {
17 17
 	Imei       string `json:"imei"`
18 18
 	OriginImei string `json:"origin_imei"`
@@ -20,7 +20,7 @@ type DeviceConf struct {
20 20
 }
21 21
 
22 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 24
 	setTagLog(k)
25 25
 }
26 26
 
@@ -29,9 +29,9 @@ func setTagLog(key string) {
29 29
 	defer conn.Close()
30 30
 
31 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 37
 // 存储ip上一次请求时间
@@ -41,7 +41,7 @@ func SetIpReqTime(ip string, reqTime int64) {
41 41
 
42 42
 	ipKey := strings.ReplaceAll(ip, ".", "")
43 43
 	redisKey := "adip_" + ipKey
44
-	conn.Do("SET", redisKey, reqTime)
44
+	_, _ = conn.Do("SET", redisKey, reqTime)
45 45
 }
46 46
 
47 47
 // 获取这个ip最近一次请求的时间
@@ -59,7 +59,7 @@ func GetIpReqTime(ip string) (int64, error) {
59 59
 		return 0, err
60 60
 	}
61 61
 	lastReqTime, _ := redis.Int64(rsp, err)
62
-	return lastReqTime,nil
62
+	return lastReqTime, nil
63 63
 }
64 64
 
65 65
 func SetMiDeviceConf(key string, d DeviceConf) error {
@@ -70,19 +70,19 @@ func SetMiDeviceConf(key string, d DeviceConf) error {
70 70
 	if err != nil {
71 71
 		return err
72 72
 	}
73
-	conn.Do("set", key, deviceConfBytes,86400)
73
+	_, _ = conn.Do("set", key, deviceConfBytes, 86400)
74 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 79
 	conn := ads_redis.RedisConn.Get()
80 80
 	defer conn.Close()
81 81
 
82 82
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
83 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 86
 	} else {
87 87
 		rd = specialDeviceNum
88 88
 	}
@@ -117,14 +117,14 @@ func SetDailyFakeDeviceConfByCityCode(cityCode int, d DeviceConf, dateInt int) e
117 117
 	if err != nil {
118 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 123
 	return nil
124 124
 }
125 125
 
126 126
 // 获取每天的设备imei
127
-func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error){
127
+func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error) {
128 128
 	conn := ads_redis.RedisConn.Get()
129 129
 	defer conn.Close()
130 130
 
@@ -166,8 +166,11 @@ func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error){
166 166
 
167 167
 	if validDeviceConf != nil {
168 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 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 196
 	if err != nil {
194 197
 		return false, err
195 198
 	}
@@ -203,5 +206,5 @@ func AddCityCodeBlackImei(cityCode int, imei string) {
203 206
 	defer conn.Close()
204 207
 
205 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 4
 	"bytes"
5 5
 	"crypto/aes"
6 6
 	"crypto/cipher"
7
-	"crypto/rand"
8
-	"encoding/base64"
9 7
 	"encoding/hex"
10
-	"io"
11 8
 )
12 9
 
13 10
 /*CBC加密 按照golang标准库的例子代码
@@ -17,19 +14,13 @@ import (
17 14
 //使用PKCS7进行填充,IOS也是7
18 15
 func pkcs7Padding(ciphertext []byte, blockSize int) []byte {
19 16
 	padding := blockSize - len(ciphertext)%blockSize
20
-	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
17
+	padtext := bytes.Repeat([]byte{byte(0)}, padding)
21 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 22
 	padding := blockSize - len(ciphertext)%blockSize
32
-	padtext := bytes.Repeat([]byte{0}, padding)//用0去填充
23
+	padtext := bytes.Repeat([]byte{0}, padding) //用0去填充
33 24
 	return append(ciphertext, padtext...)
34 25
 }
35 26
 
@@ -44,17 +35,12 @@ func AesCBCEncrypt(rawData, key []byte) ([]byte, error) {
44 35
 	blockSize := block.BlockSize()
45 36
 
46 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 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 45
 	return cipherText, nil
60 46
 }
@@ -81,7 +67,7 @@ func AesCBCDecrypt(encryptData, key []byte) ([]byte, error) {
81 67
 	// CryptBlocks can work in-place if the two arguments are the same.
82 68
 	mode.CryptBlocks(encryptData, encryptData)
83 69
 	//解填充
84
-	encryptData = ZeroPadding(encryptData, blockSize)
70
+	encryptData = pkcs7UnPadding(encryptData, blockSize)
85 71
 	return encryptData, nil
86 72
 }
87 73
 
@@ -90,7 +76,8 @@ func Encrypt(rawData, key []byte) (string, error) {
90 76
 	if err != nil {
91 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 83
 func Decrypt(rawData string, key []byte) (string, error) {
@@ -104,4 +91,3 @@ func Decrypt(rawData string, key []byte) (string, error) {
104 91
 	}
105 92
 	return string(dnData), nil
106 93
 }
107
-

+ 11 - 8
adslib/redis_data/order.go

@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/base64"
5 5
 	"encoding/json"
6 6
 	"github.com/gomodule/redigo/redis"
7
+	log "github.com/sirupsen/logrus"
7 8
 	"miads/adslib/ads_redis"
8 9
 	"miads/adslib/graylog"
9 10
 	"miads/adslib/utils"
@@ -85,10 +86,12 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
85 86
 		return []AdOrderInfo{}, err
86 87
 	}
87 88
 
89
+	log.Tracef("order infos: %s", orderIds)
88 90
 	orders := make([]AdOrderInfo, 0, 50)
89 91
 	for _, id := range orderIds {
90 92
 		order, err := getOrderInfo(id)
91 93
 		if err != nil {
94
+			log.Warnf("no order info for: %s", id)
92 95
 			continue
93 96
 		}
94 97
 
@@ -162,10 +165,10 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
162 165
 				Province        string
163 166
 				City            string
164 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 173
 				Ip:              dsp.Ip,
171 174
 				ShortMessage:    "area_result_v2",
@@ -173,10 +176,10 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
173 176
 				Province:        dsp.Province,
174 177
 				City:            dsp.City,
175 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 184
 			graylog.Log(grayLogData)
182 185
 		}

+ 26 - 25
adslib/redis_data/redis_data.go

@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"github.com/gomodule/redigo/redis"
7
+	log "github.com/sirupsen/logrus"
7 8
 	"miads/adslib"
8 9
 	"miads/adslib/ads_redis"
9 10
 	"strconv"
@@ -11,7 +12,7 @@ import (
11 12
 )
12 13
 
13 14
 type ChannelFlag struct {
14
-	Weigth      int `json:"weigth""`
15
+	Weigth      int `json:"weigth"`
15 16
 	ChannelFlag int `json:"channel_flag"`
16 17
 }
17 18
 
@@ -39,7 +40,7 @@ func GetChannelFlag(reqSource string, business string) (*ChannelFlag, error) {
39 40
 	conn := ads_redis.RedisConn.Get()
40 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 44
 	rsp, err := conn.Do("GET", redisKey)
44 45
 	if err != nil {
45 46
 		return nil, err
@@ -121,7 +122,7 @@ func GetAdsFeedbackNum(advertiser string, action string, bannerid int) (int, err
121 122
 
122 123
 	redisKey := fmt.Sprintf("adsv3_%s_%s_%d", advertiser, action, bannerid)
123 124
 	if time.Now().Unix()%100 == 0 {
124
-		conn.Do("DELETE", redisKey)
125
+		_, _ = conn.Do("DELETE", redisKey)
125 126
 	}
126 127
 
127 128
 	rsp, err := conn.Do("GET", redisKey)
@@ -164,17 +165,17 @@ func SetDistributeActionNum(advertiser string, action string, bannerid int) {
164 165
 	redisKey := fmt.Sprintf("adsv3_%s_%s_%d", advertiser, action, bannerid)
165 166
 	curTime := int(time.Now().Unix())
166 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 173
 // 获取设备+ip上报是否可以
173
-func GetDeviceIpReport(deviceid string, ip string) (bool, error) {
174
+func GetDeviceIpReport(deviceId string, ip string) (bool, error) {
174 175
 	conn := ads_redis.RedisConn.Get()
175 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 179
 	rsp, err := conn.Do("GET", redisKey)
179 180
 	if err != nil {
180 181
 		return false, err
@@ -196,11 +197,11 @@ func SetDeviceIpReport(deviceid string, ip string) {
196 197
 	defer conn.Close()
197 198
 
198 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 205
 	if advertiser == "" {
205 206
 		return
206 207
 	}
@@ -208,11 +209,11 @@ func SetAdsRequestNum(advertiser string, bannerid int) {
208 209
 	conn := ads_redis.RedisConn.Get()
209 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 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 219
 func SetAdsRealRequestNum(advertiser string) {
@@ -224,7 +225,7 @@ func SetAdsRealRequestNum(advertiser string) {
224 225
 	defer conn.Close()
225 226
 
226 227
 	redisKey := fmt.Sprintf("adsv2_request_%s", advertiser)
227
-	conn.Do("incr", redisKey)
228
+	_, _ = conn.Do("incr", redisKey)
228 229
 }
229 230
 
230 231
 // 设置skip redis
@@ -233,7 +234,7 @@ func SetSkipInfo(md5Skip string, skipUrl string) {
233 234
 	defer conn.Close()
234 235
 
235 236
 	redisKey := "su_" + md5Skip
236
-	conn.Do("set", redisKey, skipUrl, 300)
237
+	_, _ = conn.Do("set", redisKey, skipUrl, 300)
237 238
 }
238 239
 
239 240
 // 通过advertiser获取最小的script_order
@@ -261,7 +262,7 @@ func SetReqSourceView(adv string, reqSource string, source string) {
261 262
 
262 263
 	dateInt, _ := strconv.Atoi(time.Now().Format("20060102"))
263 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 328
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
328 329
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
329 330
 	rsp, err := conn.Do("GET", key)
331
+	log.Infof("%s %s", key, rsp)
330 332
 	if err != nil {
331 333
 		return 0, err
332 334
 	}
@@ -362,7 +364,7 @@ func SetPlanDispatchCount(orderId int64, dispatchType string, cnt int, curTime t
362 364
 	defer conn.Close()
363 365
 
364 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 376
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
375 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 444
 			return "", "", nil
443 445
 		}
444 446
 
445
-		conn.Do("SREM", redisKey, rsp)
447
+		_, _ = conn.Do("SREM", redisKey, rsp)
446 448
 
447 449
 		tomorrowDateInt, _ := strconv.Atoi(time.Unix(time.Now().Unix()+86400, 0).Format("20060102"))
448 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 456
 	var uaImeiInfo struct {
459 457
 		Imei string
460 458
 		Ua   string
461 459
 	}
462 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 465
 	return uaImeiInfo.Imei, uaImeiInfo.Ua, nil
465 466
 }

+ 12 - 1
go.mod

@@ -4,12 +4,23 @@ go 1.12
4 4
 
5 5
 require (
6 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 10
 	github.com/gin-gonic/gin v1.6.3
9 11
 	github.com/gomodule/redigo v2.0.0+incompatible
10 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 19
 	github.com/lionsoul2014/ip2region v2.1.0-release+incompatible
20
+	github.com/pkg/errors v0.9.1 // indirect
12 21
 	github.com/rafaeljusto/redigomock v2.4.0+incompatible
13 22
 	github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827
23
+	github.com/sirupsen/logrus v1.6.0
14 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 1
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2 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 7
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6 8
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7 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 12
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
9 13
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
10 14
 github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
11 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 17
 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
13 18
 github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
14 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 28
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
24 29
 github.com/jarcoal/httpmock v1.0.5 h1:cHtVEcTxRSX4J0je7mWPfc9BpDpqzXSJ5HbymZmyHck=
25 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 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 44
 github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
28 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 54
 github.com/lionsoul2014/ip2region v2.1.0-release+incompatible h1:FHT0RIeHl5C1G+V0mhKI+kFoBoDOPBEmF8hVhKZcmNs=
30 55
 github.com/lionsoul2014/ip2region v2.1.0-release+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI=
31 56
 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
32 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 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 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 65
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
36 66
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
37 67
 github.com/rafaeljusto/redigomock v2.4.0+incompatible h1:d7uo5MVINMxnRr20MxbgDkmZ8QRfevjOVgEa4n0OZyY=
38 68
 github.com/rafaeljusto/redigomock v2.4.0+incompatible/go.mod h1:JaY6n2sDr+z2WTsXkOmNRUfDy6FN0L6Nk7x06ndm4tY=
39 69
 github.com/robertkowalski/graylog-golang v0.0.0-20151121031040-e5295cfa2827 h1:D2Xs0bSuqpKnUOOlK4yu6lloeOs4+oD+pjbOfsxgWu0=
40 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 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 75
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
43 76
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
44 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 80
 github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
46 81
 github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
47 82
 github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
48 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 86
 golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
50 87
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
51 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 90
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
53 91
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
54 92
 gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=

Dosya farkı çok büyük olduğundan ihmal edildi
+ 138 - 8
main_test.go