jiangshuai
2023-11-08 47000c8d61e28bc590d085753c8b9ceff8546121
conf/config.go
@@ -23,30 +23,27 @@
type (
   webConf struct {
      Host      string // 本机ip地址
      Port      string // 端口号
      NodeId    string // 主账户用户名
      OssType   string // 对象存储类型
      JWTSecret string
      GrpcPort  string //grpc端口号
      Host       string // 本机ip地址
      Port       string // 端口号
      NodeId     string // 主账户用户名
      OssType    string // 对象存储类型
      JWTSecret  string
      FileServer string //文件服务器地址
      ServerId   string //服务ID
      GrpcPort   string //grpc端口号
   }
   localConf struct {
      StorePath string // 本地文件存储路径
   }
   grpcServerConf struct {
      ApsAddr string //aps服务grpc地址
   }
)
var (
   WebConf        = &webConf{}
   LogConf        = &logx.Conf{}
   DbConf         = &mysqlx.Conf{}
   LocalConf      = &localConf{}
   Viper          *viper.Viper
   GrpcServerConf = &grpcServerConf{}
   WebConf   = &webConf{}
   LogConf   = &logx.Conf{}
   DbConf    = &mysqlx.Conf{}
   LocalConf = &localConf{}
   Viper     *viper.Viper
)
func Init() error {
@@ -61,21 +58,13 @@
   }
   read2Conf(Viper)
   nodeId := os.Getenv("NODE_ID")    // 主账户用户名
   host := os.Getenv("HOST")         // 本机IP地址
   GrpcPort := os.Getenv("WMS_GRPC") // 只对外提供grpc服务,本服务不用
   apsAddr := os.Getenv("APS_GRPC")
   if len(GrpcPort) > 0 {
      WebConf.GrpcPort = GrpcPort
   }
   nodeId := os.Getenv("NODE_ID") // 主账户用户名
   host := os.Getenv("HOST")      // 本机IP地址
   if len(nodeId) > 0 {
      WebConf.NodeId = nodeId
   }
   if len(host) > 0 {
      WebConf.Host = host
   }
   if len(apsAddr) > 0 {
      GrpcServerConf.ApsAddr = apsAddr
   }
   DBHost := os.Getenv("DB_HOST")
@@ -99,7 +88,6 @@
   _ = v.UnmarshalKey("log", LogConf)
   _ = v.UnmarshalKey("db", DbConf)
   _ = v.UnmarshalKey("local", LocalConf)
   _ = v.UnmarshalKey("grpcServer", GrpcServerConf)
   showConfig()
}
@@ -109,6 +97,5 @@
   log.Printf("   LogConf:                %+v", LogConf)
   log.Printf("   DbConf:                 %+v", DbConf)
   log.Printf("   LocalConf:               %+v", LocalConf)
   log.Printf("   GrpcServerConf:               %+v", GrpcServerConf)
   log.Println("......................................................")
}