mh_goadmin_server/tools/config/config.go
chenlin d3f485ecda 1.增加零售订单相关接口;
2.增加查询会员手机号接口;
3.修改库存导入串码规则;
4.查询库存详情增加出参求和字段;
5.日志初始化位置调整;
2023-12-19 18:21:44 +08:00

94 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"github.com/spf13/viper"
)
// 数据库配置项
var cfgDatabase *viper.Viper
// 应用配置项
var cfgApplication *viper.Viper
// Token配置项
var cfgJwt *viper.Viper
// Log配置项
var cfgLogger *viper.Viper
// Ssl配置项 非必须
var cfgSsl *viper.Viper
// 代码生成配置项 非必须
var cfgGen *viper.Viper
// 导出文件配置项 非必须
var cfgExport *viper.Viper
// Setup 载入配置文件
func Setup(path string) {
viper.SetConfigFile(path)
content, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
}
//Replace environment variables
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
if err != nil {
log.Fatal(fmt.Sprintf("Parse config file fail: %s", err.Error()))
}
cfgDatabase = viper.Sub("settings.database")
if cfgDatabase == nil {
panic("No found settings.database in the configuration")
}
DatabaseConfig = InitDatabase(cfgDatabase)
cfgApplication = viper.Sub("settings.application")
if cfgApplication == nil {
panic("No found settings.application in the configuration")
}
ApplicationConfig = InitApplication(cfgApplication)
cfgJwt = viper.Sub("settings.jwt")
if cfgJwt == nil {
panic("No found settings.jwt in the configuration")
}
JwtConfig = InitJwt(cfgJwt)
cfgLogger = viper.Sub("settings.logger")
if cfgLogger == nil {
panic("No found settings.logger in the configuration")
}
LoggerConfig = InitLog(cfgLogger)
cfgSsl = viper.Sub("settings.ssl")
if cfgSsl == nil {
// Ssl不是系统强制要求的配置默认可以不用配置将设置为关闭状态
fmt.Println("warning config not found settings.ssl in the configuration")
SslConfig = new(Ssl)
SslConfig.Enable = false
} else {
SslConfig = InitSsl(cfgSsl)
}
cfgGen = viper.Sub("settings.gen")
if cfgGen == nil {
panic("No found settings.gen")
}
GenConfig = InitGen(cfgGen)
cfgExport = viper.Sub("settings.export")
if cfgExport == nil {
panic("No found settings.export")
}
ExportConfig = InitExport(cfgExport)
}