作者 yangfu

k8s

1 [dev] 1 [dev]
2 #数据库相关 2 #数据库相关
3 -data_source = "root:123456@tcp(127.0.0.1:3306)/opportunity?loc=Local"  
4 -#data_source = "root:sutianxia2015@tcp(115.29.205.99:3306)/ability_display"  
5 -#data_source = "root:root@tcp(localhost:3306)/ability_display?loc=Local" 3 +mysql_user = "${MYSQL_USER||root}"
  4 +mysql_password = "${MYSQL_PASSWORD||123456}"
  5 +mysql_host = "${MYSQL_HOST||192.168.100.102}"
  6 +mysql_port = "${MYSQL_PORT||3306}"
  7 +mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
  8 +
  9 +#日志
  10 +log_level = "${LOG_LEVEL||debug}"
  11 +aliyun_logs_access ="app.log"
  12 +
6 13
7 #redis相关配置 14 #redis相关配置
8 -redis_add_port = "127.0.0.1:6379" 15 +redis_add_port = "192.168.100.102:6379"
9 redis_auth = "123456" 16 redis_auth = "123456"
10 17
11 #sms相关配置 18 #sms相关配置
@@ -14,8 +21,8 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5" @@ -14,8 +21,8 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
14 21
15 #存储 http://ability.fjmaimaimai.com:8080/ 22 #存储 http://ability.fjmaimaimai.com:8080/
16 source_host ="http://192.168.139.131:8080/" 23 source_host ="http://192.168.139.131:8080/"
17 -source_virtual_path=file/ab  
18 -source_path =/home/tiptok/www/ab 24 +source_virtual_path=file/opp
  25 +source_path =/www/opp
19 26
20 #网易云信 IM 27 #网易云信 IM
21 net_im_base_url ="https://api.netease.im/nimserver" 28 net_im_base_url ="https://api.netease.im/nimserver"
1 [prod] 1 [prod]
2 #数据库相关 2 #数据库相关
3 -data_source = "root:123456@tcp(192.168.100.102:3306)/ability_display?loc=Local" 3 +mysql_user = "${MYSQL_USER||root}"
  4 +mysql_password = "${MYSQL_PASSWORD||123456}"
  5 +mysql_host = "${MYSQL_HOST||192.168.100.102}"
  6 +mysql_port = "${MYSQL_PORT||3306}"
  7 +mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
  8 +
  9 +#日志
  10 +log_level = "${LOG_LEVEL||debug}"
  11 +aliyun_logs_access ="app.log"
4 12
5 13
6 #redis相关配置 14 #redis相关配置
@@ -13,8 +21,8 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5" @@ -13,8 +21,8 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
13 21
14 #存储 http://ability.fjmaimaimai.com:8080/ 22 #存储 http://ability.fjmaimaimai.com:8080/
15 source_host ="http://192.168.139.131:8080/" 23 source_host ="http://192.168.139.131:8080/"
16 -source_virtual_path=file/ab  
17 -source_path =/home/tiptok/www/ab 24 +source_virtual_path=file/opp
  25 +source_path =/www/opp
18 26
19 #网易云信 IM 27 #网易云信 IM
20 net_im_base_url ="https://api.netease.im/nimserver" 28 net_im_base_url ="https://api.netease.im/nimserver"
  1 +package utils
  2 +
  3 +import "github.com/astaxie/beego"
  4 +
  5 +func init() {
  6 + logLevelMap := make(map[string]int)
  7 + logLevelMap["debug"] = beego.LevelDebug
  8 + logLevelMap["info"] = beego.LevelInformational
  9 + logLevelMap["warn"] = beego.LevelWarning
  10 + logLevelMap["error"] = beego.LevelError
  11 + logLevelMap["fatal"] = beego.LevelEmergency
  12 +}
  13 +
  14 +func ResolveLogLevel(level string) int {
  15 + switch level {
  16 + case "debug":
  17 + return beego.LevelDebug
  18 + case "info":
  19 + return beego.LevelInformational
  20 + case "warn":
  21 + return beego.LevelWarning
  22 + case "error":
  23 + return beego.LevelError
  24 + case "fatal":
  25 + return beego.LevelEmergency
  26 + }
  27 + return beego.LevelInformational
  28 +}
1 package main 1 package main
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/astaxie/beego" 5 "github.com/astaxie/beego"
5 _ "github.com/go-sql-driver/mysql" 6 _ "github.com/go-sql-driver/mysql"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
@@ -10,6 +11,7 @@ import ( @@ -10,6 +11,7 @@ import (
10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" 11 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
11 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" 12 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
12 "opp/controllers" 13 "opp/controllers"
  14 + "opp/internal/utils"
13 "opp/protocol" 15 "opp/protocol"
14 _ "opp/routers" 16 _ "opp/routers"
15 "opp/services/im" 17 "opp/services/im"
@@ -19,23 +21,30 @@ import ( @@ -19,23 +21,30 @@ import (
19 func init() { 21 func init() {
20 time.Local = time.FixedZone("CST", 3600*8) 22 time.Local = time.FixedZone("CST", 3600*8)
21 log.InitLog(config.Logger{ 23 log.InitLog(config.Logger{
22 - Filename: "app.log",  
23 - Level: "7",  
24 - })  
25 - //TODO:kafka配置  
26 - log.InitKafkaLogger(log.KafkaConfig{  
27 - Topic: "ability",  
28 - Addrs: []string{"127.0.0.1:9092"},  
29 - Level: 6, 24 + Filename: beego.AppConfig.String("aliyun_logs_access"),
  25 + Level: fmt.Sprintf("%v", utils.ResolveLogLevel(beego.AppConfig.String("log_level"))),
30 }) 26 })
  27 + //TODO:kafka log配置
  28 + //log.InitKafkaLogger(log.KafkaConfig{
  29 + // Topic: "ability",
  30 + // Addrs: []string{"127.0.0.1:9092"},
  31 + // Level: 6,
  32 + //})
31 err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0") 33 err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0")
32 if err != nil { 34 if err != nil {
33 log.Fatal(err, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth")) 35 log.Fatal(err, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"))
34 //panic(err) 36 //panic(err)
35 } 37 }
  38 + dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai",
  39 + beego.AppConfig.String("mysql_user"),
  40 + beego.AppConfig.String("mysql_password"),
  41 + beego.AppConfig.String("mysql_host"),
  42 + beego.AppConfig.String("mysql_port"),
  43 + beego.AppConfig.String("mysql_db_name"),
  44 + )
36 orm.NewBeeormEngine(config.Mysql{ 45 orm.NewBeeormEngine(config.Mysql{
37 //AliasName: "default", 46 //AliasName: "default",
38 - DataSource: beego.AppConfig.String("data_source"), 47 + DataSource: dataSource,
39 MaxIdle: 100, 48 MaxIdle: 100,
40 MaxOpen: 100, 49 MaxOpen: 100,
41 }) 50 })