Browse Source

调整配置

jiantaoli 4 years ago
parent
commit
4526afa9b8
6 changed files with 14 additions and 5 deletions
  1. 1 1
      ads_handler.go
  2. 3 1
      adslib/config.go
  3. 3 1
      adslib/ip2region/ip2region_test.go
  4. 2 0
      conf/config.toml
  5. BIN
      conf/ip2region.db
  6. 5 2
      main_test.go

+ 1 - 1
ads_handler.go

@@ -59,7 +59,7 @@ func setupLogger(logName string, logLevel log.Level) {
59
 }
59
 }
60
 
60
 
61
 func adsHandler(c *gin.Context) {
61
 func adsHandler(c *gin.Context) {
62
-	setupLogger("log/ads.log", log.TraceLevel)
62
+	setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
63
 	c.Header("Content-Type", "application/json")
63
 	c.Header("Content-Type", "application/json")
64
 
64
 
65
 	request := adslib.Request{}
65
 	request := adslib.Request{}

+ 3 - 1
adslib/config.go

@@ -22,6 +22,8 @@ type SvrConf struct {
22
 	ActionWeight       ActionWeight                          `toml:"action_weight"`
22
 	ActionWeight       ActionWeight                          `toml:"action_weight"`
23
 	CombinationActions map[string][]CombinationActionsConf   `toml:"combination_actions"`
23
 	CombinationActions map[string][]CombinationActionsConf   `toml:"combination_actions"`
24
 	SecretKey          string                                `toml:"secret_key"`
24
 	SecretKey          string                                `toml:"secret_key"`
25
+	Ip2RegionFile      string                                `toml:"ip2region_file"`
26
+	LogPath            string                                `toml:"log_path"`
25
 }
27
 }
26
 type FlogControlItem struct {
28
 type FlogControlItem struct {
27
 	Percent  int `toml:"percent"`
29
 	Percent  int `toml:"percent"`
@@ -46,7 +48,7 @@ var svrConf SvrConf
46
 var once sync.Once
48
 var once sync.Once
47
 
49
 
48
 func GetConf() *SvrConf {
50
 func GetConf() *SvrConf {
49
-	once.Do(func () {
51
+	once.Do(func() {
50
 		_, err := toml.DecodeFile("./conf/config.toml", &svrConf)
52
 		_, err := toml.DecodeFile("./conf/config.toml", &svrConf)
51
 		if err != nil {
53
 		if err != nil {
52
 			panic(err)
54
 			panic(err)

+ 3 - 1
adslib/ip2region/ip2region_test.go

@@ -3,13 +3,15 @@ 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
 	"testing"
7
 	"testing"
7
 )
8
 )
8
 
9
 
9
 var r *ip2region.Ip2Region
10
 var r *ip2region.Ip2Region
11
+
10
 func init() {
12
 func init() {
11
 	var err error
13
 	var err error
12
-	r, err = ip2region.New("../../conf/ip2region.db")
14
+	r, err = ip2region.New(adslib.GetConf().Ip2RegionFile)
13
 	if err != nil {
15
 	if err != nil {
14
 		fmt.Printf("%s", err)
16
 		fmt.Printf("%s", err)
15
 	}
17
 	}

File diff suppressed because it is too large
+ 2 - 0
conf/config.toml


BIN
conf/ip2region.db


File diff suppressed because it is too large
+ 5 - 2
main_test.go