zhangzengfei
2024-09-26 88b1f1d1d14a8fe9e3dde2f363a89d821fc0e641
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
@@ -36,6 +37,7 @@
   v.SetConfigName("compare")
   v.AddConfigPath("./")
   v.AddConfigPath("./config/")
   v.AddConfigPath("../config/")
   err = v.ReadInConfig()
   if err != nil {
      fmt.Printf("error on parsing configuration file, %s, config file compare.yaml\n", err.Error())
@@ -52,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
   }
}