79 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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
 | |
| 	}
 | |
| 	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/%s", os.Getenv(model.MODE_ENV), model.SERVER_DUBBOGO_CONFIG)); err != nil {
 | |
| 			return
 | |
| 		}
 | |
| 	}
 | |
| 	iniConf = fmt.Sprintf("./conf/%s", 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())
 | |
| 	}
 | |
| 
 | |
| }
 |