exhibition-main/internal/config/app_config.go

79 lines
1.6 KiB
Go
Raw Normal View History

2024-01-31 09:04:43 +00:00
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)
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
}
2024-02-01 05:44:54 +00:00
Bos struct {
AccessKeyId string
AccessKeySecret string
Endpoint string
Host string
BucketName string
BosBaseDir string
CdnHost string
}
2024-01-31 09:04:43 +00:00
}
func GetConf() (iniConf string, err error) {
if os.Getenv(model.MODE_ENV) != "" {
2024-02-18 05:32:12 +00:00
if err = os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s%s", os.Getenv(model.MODE_ENV), model.SERVER_DUBBOGO_CONFIG)); err != nil {
2024-01-31 09:04:43 +00:00
return
}
}
2024-02-18 05:32:12 +00:00
iniConf = fmt.Sprintf("./conf/%s", model.SERVER_CONFIG)
2024-01-31 09:04:43 +00:00
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())
}
}