zhangzengfei
2024-07-06 635f849d70ae31df42dab56dacf62727a313db28
config/config.go
@@ -8,18 +8,19 @@
   "github.com/spf13/viper"
)
type database struct {
type mainConfig struct {
   ServePort   int    `mapstructure:"servePort"`
   WorkerNum   int    `mapstructure:"workerNum"`
   MysqlAddr   string `mapstructure:"mysqlAddr"`
   Username    string `mapstructure:"username"`
   Password    string `mapstructure:"password"`
   Database    string `mapstructure:"database"`
   PersonTable string `mapstructure:"personTable"`
   ServePort   int    `mapstructure:"servePort"`
}
var DbPersonCompInfo = &database{}
var MainConf = &mainConfig{}
type LogConfig struct {
type logConfig struct {
   Path       string `mapstructure:"path"`       //日志存储路径
   Level      int    `mapstructure:"level"`      //日志等级
   MaxSize    int    `mapstructure:"maxSize"`    //日志文件大小上限
@@ -27,7 +28,7 @@
   MaxAge     int    `mapstructure:"maxAge"`     //保留压缩包天数
}
var LogConf = &LogConfig{}
var LogConf = &logConfig{}
func Init() error {
   var err error
@@ -53,8 +54,12 @@
}
func read2Conf(v *viper.Viper) {
   v.UnmarshalKey("database", DbPersonCompInfo)
   v.UnmarshalKey("main", MainConf)
   v.UnmarshalKey("log", LogConf)
   logger.SetLevel(LogConf.Level)
   if MainConf.WorkerNum == 0 {
      MainConf.WorkerNum = 30
   }
}