package config import ( "dubbo.apache.org/dubbo-go/v3/common/constant" "fmt" "github.com/exhibition-main/internal/model" "github.com/spf13/viper" "os" ) var Data = new(AppConfig) var ( AppMode string HttpPort string Key string Cert string IsHttps bool RunHttps bool Domain string OssDomain string ServerDM string Env string DriverUrl string AppointUrl string MaterialHost string BosAk string BosSk string BosBucketName string BosBaseDir string BosUrl string BosHttp string BosDomain string ProjectMapDir string JaegerHost string JaegerOpen bool Cron bool DingAccessToken string DingUrl string HolidayID string HolidaySecret string HolidaySingleUrl string HolidayMultiUrl string ErpAk string ErpSk string // rabbitmq RabbitmqUser string RabbitmqPassword string RabbitmqHost string RabbitmqPort int RabbitmqVhost string RabbitmqVhostArtwork string RedisDB int RedisAddr string RedisPw string //shop配置 ShopHost string //ShopDetail string // 地图 MapAppCode string // es ElasticHost string SendIndexesUrl string ChatGptHost string ApiHost string Level string Filename string MaxSize string MaxAge string MaxBackups string YearGiftCheckHost string Aliyun struct { AccessKeyId string AccessKeySecret string } ) type AppConfig struct { System struct { Domain string Mode string NodeNum int32 Port int32 KeyPath string `mapstructure:"key_path"` CertPath string `mapstructure:"cert_path"` IsHttps bool `mapstructure:"is_https"` Cron bool } Redis struct { Db uint8 Addr string Password string } ZapLog struct { Level string `mapstructure:"level"` Filename string `mapstructure:"filename"` MaxSize int `mapstructure:"max_size"` MaxAge int `mapstructure:"max_age"` MaxBackups int `mapstructure:"max_backups"` } Jaeger struct { Addr string Open bool } Jwt struct { Key string Expire int32 } Bos struct { AccessKeyId string AccessKeySecret string Endpoint string Host string BucketName string BosBaseDir string CdnHost string } } func GetConf() (iniConf string, err error) { if os.Getenv(model.MODE_ENV) != "" { if err = os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s", model.SERVER_DUBBOGO_CONFIG)); err != nil { return } } iniConf = fmt.Sprintf("./conf/%s/%s", os.Getenv(model.MODE_ENV), model.SERVER_CONFIG) return } func GetOptions() { iniConf, err := GetConf() viper.SetConfigFile(iniConf) err = viper.ReadInConfig() if err != nil { panic("viper.ReadInConfig failed" + err.Error()) return } if err = viper.Unmarshal(Data); err != nil { panic("viper.Unmarshal failed" + err.Error()) } }