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
 		log.WithField("request_id", dspInfo.RequestId).Infof("freq control conf: %+v", freqControlConf)
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
 		c.String(404, "get req channel flag failed: %s", err)
191
 		c.String(404, "get req channel flag failed: %s", err)
190
 		return
192
 		return
191
 	}
193
 	}
194
+
192
 	flowWeight := reqChannelFlag.Weigth
195
 	flowWeight := reqChannelFlag.Weigth
193
 	flowRandomNum := rand.Intn(100)
196
 	flowRandomNum := rand.Intn(100)
194
 
197
 

+ 2 - 1
adslib/ip2region/ip2region.go

@@ -3,10 +3,11 @@ package ip2region
3
 import (
3
 import (
4
 	"fmt"
4
 	"fmt"
5
 	"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
5
 	"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
6
+	"miads/adslib"
6
 )
7
 )
7
 
8
 
8
 func Ip2Region(ip string) (*ip2region.IpInfo, error) {
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
 	if region != nil {
11
 	if region != nil {
11
 		defer region.Close()
12
 		defer region.Close()
12
 	}
13
 	}

+ 4 - 5
main.go

@@ -1,7 +1,6 @@
1
 package main
1
 package main
2
 
2
 
3
 import (
3
 import (
4
-	"fmt"
5
 	"github.com/gin-gonic/gin"
4
 	"github.com/gin-gonic/gin"
6
 	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
5
 	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
7
 	"io"
6
 	"io"
@@ -51,10 +50,10 @@ func main() {
51
 	adslib.GetConf()
50
 	adslib.GetConf()
52
 	setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
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
 	r := setupRouter()
58
 	r := setupRouter()
60
 	endless.ListenAndServe(":8080", r)
59
 	endless.ListenAndServe(":8080", r)

+ 3 - 1
makefile

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