Browse Source

修复崩溃

jiantao 4 years ago
parent
commit
17df68e8ba
4 changed files with 16 additions and 11 deletions
  1. 7 4
      ads_handler.go
  2. 2 1
      adslib/ip2region/ip2region.go
  3. 4 5
      main.go
  4. 3 1
      makefile

+ 7 - 4
ads_handler.go

@@ -146,10 +146,12 @@ func adsHandler(c *gin.Context) {
146 146
 		}
147 147
 
148 148
 		log.WithField("request_id", dspInfo.RequestId).Infof("freq control conf: %+v", freqControlConf)
149
-		hour, _ := strconv.Atoi(time.Now().Format("01"))
150
-		tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
151
-		if ok {
152
-			freqControlInterval = tmpControlInterval
149
+		if freqControlConf != nil {
150
+			hour, _ := strconv.Atoi(time.Now().Format("01"))
151
+			tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
152
+			if ok {
153
+				freqControlInterval = tmpControlInterval
154
+			}
153 155
 		}
154 156
 	}
155 157
 
@@ -189,6 +191,7 @@ func adsHandler(c *gin.Context) {
189 191
 		c.String(404, "get req channel flag failed: %s", err)
190 192
 		return
191 193
 	}
194
+
192 195
 	flowWeight := reqChannelFlag.Weigth
193 196
 	flowRandomNum := rand.Intn(100)
194 197
 

+ 2 - 1
adslib/ip2region/ip2region.go

@@ -3,10 +3,11 @@ package ip2region
3 3
 import (
4 4
 	"fmt"
5 5
 	"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
6
+	"miads/adslib"
6 7
 )
7 8
 
8 9
 func Ip2Region(ip string) (*ip2region.IpInfo, error) {
9
-	region, err := ip2region.New("./conf/ip2region_20200113.db")
10
+	region, err := ip2region.New(adslib.GetConf().Ip2RegionFile)
10 11
 	if region != nil {
11 12
 		defer region.Close()
12 13
 	}

+ 4 - 5
main.go

@@ -1,7 +1,6 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"github.com/gin-gonic/gin"
6 5
 	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
7 6
 	"io"
@@ -51,10 +50,10 @@ func main() {
51 50
 	adslib.GetConf()
52 51
 	setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
53 52
 
54
-	if ads_redis.RedisConn.ActiveCount() == 0 {
55
-		fmt.Printf("setup redis failed, no active redis")
56
-		return
57
-	}
53
+	//if ads_redis.RedisConn.ActiveCount() == 0 {
54
+	//	fmt.Printf("setup redis failed, no active redis")
55
+	//	return
56
+	//}
58 57
 
59 58
 	r := setupRouter()
60 59
 	endless.ListenAndServe(":8080", r)

+ 3 - 1
makefile

@@ -1,4 +1,6 @@
1
-miads:*.go
1
+.PHONY:miads
2
+
3
+miads:
2 4
 	go build .
3 5
 
4 6
 clean: