|
@@ -0,0 +1,142 @@
|
|
|
+package common
|
|
|
+
|
|
|
+import (
|
|
|
+ "flag"
|
|
|
+ "log"
|
|
|
+ "strings"
|
|
|
+
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/mysql"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/filecenter"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
|
|
|
+ "bp.jydev.jianyu360.cn/CRM/application/api/internal/config"
|
|
|
+ "bp.jydev.jianyu360.cn/CRM/application/entity"
|
|
|
+ "bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/basecenter"
|
|
|
+ "github.com/zeromicro/go-zero/core/conf"
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
+)
|
|
|
+
|
|
|
+var configFile = flag.String("fs", "etc/bicenter.yaml", "the config file")
|
|
|
+var C config.Config
|
|
|
+
|
|
|
+var logFile = flag.String("lf", "etc/logs.yaml", "the config file")
|
|
|
+var logc entity.Logc
|
|
|
+
|
|
|
+var dbFile = flag.String("df", "etc/db.yaml", "the db file")
|
|
|
+var DB config.Db
|
|
|
+
|
|
|
+var (
|
|
|
+ MgoBidding mongodb.MongodbSim
|
|
|
+ MgoEnt mongodb.MongodbSim
|
|
|
+ MainMysql *mysql.Mysql
|
|
|
+ BaseMysql *mysql.Mysql
|
|
|
+ CrmMysql *mysql.Mysql
|
|
|
+ Mgo mongodb.MongodbSim
|
|
|
+ UserCenterRpc usercenter.UserCenter
|
|
|
+ FileCenterRpc filecenter.FileCenter
|
|
|
+ BaseCenterRpc basecenter.BaseCenter
|
|
|
+)
|
|
|
+
|
|
|
+func init() {
|
|
|
+ conf.MustLoad(*configFile, &C)
|
|
|
+ log.Println("初始化配置") //
|
|
|
+
|
|
|
+ //初始化日志信息
|
|
|
+ conf.MustLoad(*logFile, &logc)
|
|
|
+ if len(logc.Level) > 0 {
|
|
|
+ for _, v := range logc.Level {
|
|
|
+ logx.MustSetup(logx.LogConf{
|
|
|
+ Mode: logc.Mode,
|
|
|
+ Path: logc.Path,
|
|
|
+ Level: v,
|
|
|
+ KeepDays: logc.KeepDays,
|
|
|
+ })
|
|
|
+ logx.Info(v, "--日志记录")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conf.MustLoad(*dbFile, &DB)
|
|
|
+ //初始化mysql
|
|
|
+ if DB.Mysql.Main.Address != "" {
|
|
|
+ log.Println("--初始化 main mysql--")
|
|
|
+ MainMysql = &mysql.Mysql{
|
|
|
+ Address: DB.Mysql.Main.Address,
|
|
|
+ UserName: DB.Mysql.Main.UserName,
|
|
|
+ PassWord: DB.Mysql.Main.Password,
|
|
|
+ DBName: DB.Mysql.Main.DbName,
|
|
|
+ MaxOpenConns: DB.Mysql.Main.MaxOpenConns,
|
|
|
+ MaxIdleConns: DB.Mysql.Main.MaxIdleConns,
|
|
|
+ }
|
|
|
+ MainMysql.Init()
|
|
|
+ }
|
|
|
+ if DB.Mysql.BaseService.Address != "" {
|
|
|
+ log.Println("--初始化 base mysql--")
|
|
|
+ BaseMysql = &mysql.Mysql{
|
|
|
+ Address: DB.Mysql.BaseService.Address,
|
|
|
+ UserName: DB.Mysql.BaseService.UserName,
|
|
|
+ PassWord: DB.Mysql.BaseService.Password,
|
|
|
+ DBName: DB.Mysql.BaseService.DbName,
|
|
|
+ MaxOpenConns: DB.Mysql.BaseService.MaxOpenConns,
|
|
|
+ MaxIdleConns: DB.Mysql.BaseService.MaxIdleConns,
|
|
|
+ }
|
|
|
+ BaseMysql.Init()
|
|
|
+ }
|
|
|
+ if DB.Mysql.CrmService.Address != "" {
|
|
|
+ log.Println("--初始化 crm mysql--")
|
|
|
+ CrmMysql = &mysql.Mysql{
|
|
|
+ Address: DB.Mysql.CrmService.Address,
|
|
|
+ UserName: DB.Mysql.CrmService.UserName,
|
|
|
+ PassWord: DB.Mysql.CrmService.Password,
|
|
|
+ DBName: DB.Mysql.CrmService.DbName,
|
|
|
+ MaxOpenConns: DB.Mysql.CrmService.MaxOpenConns,
|
|
|
+ MaxIdleConns: DB.Mysql.CrmService.MaxIdleConns,
|
|
|
+ }
|
|
|
+ CrmMysql.Init()
|
|
|
+ }
|
|
|
+ //初始化数据库配置
|
|
|
+ rm := DB.Redis
|
|
|
+ if len(rm.Addr) > 0 {
|
|
|
+ logx.Info("--初始化 redis--")
|
|
|
+ redis.InitRedisBySize(strings.Join(rm.Addr, ","), 100, 30, 300)
|
|
|
+ }
|
|
|
+ if DB.Mongo.Main.Address != "" {
|
|
|
+ logx.Info("--初始化 mongodb--")
|
|
|
+ Mgo = mongodb.MongodbSim{
|
|
|
+ MongodbAddr: DB.Mongo.Main.Address,
|
|
|
+ Size: DB.Mongo.Main.Size,
|
|
|
+ DbName: DB.Mongo.Main.DbName,
|
|
|
+ }
|
|
|
+ Mgo.InitPool()
|
|
|
+ }
|
|
|
+ if DB.Mongo.Bidding.Address != "" {
|
|
|
+ logx.Info("--初始化 mongodb Bidding --")
|
|
|
+ MgoBidding = mongodb.MongodbSim{
|
|
|
+ MongodbAddr: DB.Mongo.Bidding.Address,
|
|
|
+ Size: DB.Mongo.Bidding.Size,
|
|
|
+ DbName: DB.Mongo.Bidding.DbName,
|
|
|
+ Password: DB.Mongo.Bidding.Password,
|
|
|
+ UserName: DB.Mongo.Bidding.UserName,
|
|
|
+ }
|
|
|
+ MgoBidding.InitPool()
|
|
|
+ }
|
|
|
+ if DB.Mongo.Ent.Address != "" {
|
|
|
+ logx.Info("--初始化 mongodb ent --")
|
|
|
+ MgoEnt = mongodb.MongodbSim{
|
|
|
+ MongodbAddr: DB.Mongo.Ent.Address,
|
|
|
+ Size: DB.Mongo.Ent.Size,
|
|
|
+ DbName: DB.Mongo.Ent.DbName,
|
|
|
+ Password: DB.Mongo.Ent.Password,
|
|
|
+ UserName: DB.Mongo.Ent.UserName,
|
|
|
+ }
|
|
|
+ MgoEnt.InitPool()
|
|
|
+ }
|
|
|
+ //初始化 elasticsearch
|
|
|
+ if DB.Es.Addr != "" {
|
|
|
+ log.Println("--初始化 elasticsearch--")
|
|
|
+ NewEs(DB.Es.Version, DB.Es.Addr, DB.Es.Size, DB.Es.UserName, DB.Es.Password)
|
|
|
+ }
|
|
|
+ //UserCenterRpc = usercenter.NewUserCenter(zrpc.MustNewClient(C.UserCenterRpc))
|
|
|
+ //FileCenterRpc = filecenter.NewFileCenter(zrpc.MustNewClient(C.FileCenterRpc))
|
|
|
+ //BaseCenterRpc = basecenter.NewBaseCenter(zrpc.MustNewClient(C.BaseCenterRpc))
|
|
|
+}
|