main.go
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"github.com/astaxie/beego"
_ "github.com/go-sql-driver/mysql"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
"opp/internal/utils"
_ "opp/routers"
"os"
"time"
)
func init() {
time.Local = time.FixedZone("CST", 3600*8)
log.InitLog(config.Logger{
Filename: beego.AppConfig.String("aliyun_logs_access"),
Level: fmt.Sprintf("%v", utils.ResolveLogLevel(beego.AppConfig.String("log_level"))),
})
//TODO:kafka log配置
//log.InitKafkaLogger(log.KafkaConfig{
// Topic: "ability",
// Addrs: []string{"127.0.0.1:9092"},
// Level: 6,
//})
redisSource := fmt.Sprintf("%v:%v", beego.AppConfig.String("redis_add"), beego.AppConfig.String("redis_add_port"))
err := redis.InitWithDb(100, redisSource, beego.AppConfig.String("redis_auth"), "0")
log.Info(fmt.Sprintf("init redis:%v", redisSource))
if err != nil {
log.Fatal("connect to redis error address:", beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), err)
//panic(err)
}
dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai",
beego.AppConfig.String("mysql_user"),
beego.AppConfig.String("mysql_password"),
beego.AppConfig.String("mysql_host"),
beego.AppConfig.String("mysql_port"),
beego.AppConfig.String("mysql_db_name"),
)
log.Info(fmt.Sprintf("init mysql:%v", dataSource))
orm.NewBeeormEngine(config.Mysql{
//AliasName: "default",
DataSource: dataSource,
MaxIdle: 100,
MaxOpen: 100,
})
//TODO:邮件服务配置
common.InitMailService(&common.MailConfig{
//Host:"smtp.qq.com",
//Port:465,
//From:"785410885@qq.com",
//Password:"ibfduqhfmgypbffe", //授权码
//IsUseSsl:true,
})
//im.InitImClient(beego.AppConfig.String("net_im_base_url"), beego.AppConfig.String("net_im_app_key"), beego.AppConfig.String("net_im_app_secret"))
websocket.InitWebsocketConnmgrs(10)
log.Info(fmt.Sprintf("env MYSQL_USER:%v", os.Getenv("MYSQL_USER")))
log.Info(fmt.Sprintf("env MYSQL_PASSWORD:%v", os.Getenv("MYSQL_PASSWORD")))
log.Info(fmt.Sprintf("env MYSQL_HOST:%v", os.Getenv("MYSQL_HOST")))
log.Info(fmt.Sprintf("env MYSQL_PORT:%v", os.Getenv("MYSQL_PORT")))
log.Info(fmt.Sprintf("env MYSQL_DB_NAME:%v", os.Getenv("MYSQL_DB_NAME")))
log.Info(fmt.Sprintf("env LOG_LEVEL:%v", os.Getenv("LOG_LEVEL")))
log.Info(fmt.Sprintf("env aliyun_logs_access:%v", os.Getenv("aliyun_logs_access")))
log.Info(fmt.Sprintf("env REDIS_HOST:%v", os.Getenv("REDIS_HOST")))
log.Info(fmt.Sprintf("env REDIS_PORT:%v", os.Getenv("REDIS_PORT")))
log.Info(fmt.Sprintf("env aliyun_file_access:%v", os.Getenv("aliyun_file_access")))
}
func main() {
defer func() {
log.Info("app on stop!")
}()
log.Info("app on start!")
log.Info("Beego Run Mode:", beego.BConfig.RunMode)
beego.Run()
}