| | |
| | | "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"` //日志文件大小上限 |
| | |
| | | MaxAge int `mapstructure:"maxAge"` //保留压缩包天数 |
| | | } |
| | | |
| | | var LogConf = &LogConfig{} |
| | | var LogConf = &logConfig{} |
| | | |
| | | func Init() error { |
| | | var err error |
| | |
| | | } |
| | | |
| | | 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 |
| | | } |
| | | } |