From 8475853b31525e0490c4a6518b1e36ce60ccba13 Mon Sep 17 00:00:00 2001 From: SliverHorn <503551462@qq.com> Date: Thu, 15 Oct 2020 11:55:55 +0800 Subject: [PATCH] repair config env error --- server/config.yaml | 1 - server/config/system.go | 1 - server/core/config.go | 9 ++++----- server/utils/constant.go | 6 ++++++ 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 server/utils/constant.go diff --git a/server/config.yaml b/server/config.yaml index 0e478e1e..c7f8fdb6 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -42,7 +42,6 @@ system: addr: 8888 db-type: 'mysql' oss-type: 'local' - config-env: 'GVA_CONFIG' need-init-data: false use-multipoint: false diff --git a/server/config/system.go b/server/config/system.go index 53f52ad0..67e5406f 100644 --- a/server/config/system.go +++ b/server/config/system.go @@ -5,7 +5,6 @@ type System struct { Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` - ConfigEnv string `mapstructure:"config-env" json:"configEnv" yaml:"config-env"` NeedInitData bool `mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"` UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` } diff --git a/server/core/config.go b/server/core/config.go index e3ac9094..317fce67 100644 --- a/server/core/config.go +++ b/server/core/config.go @@ -5,6 +5,7 @@ import ( "fmt" "gin-vue-admin/global" _ "gin-vue-admin/packfile" + "gin-vue-admin/utils" "github.com/fsnotify/fsnotify" "github.com/spf13/viper" "os" @@ -12,15 +13,13 @@ import ( var config string -const defaultConfigFile = "config.yaml" - func init() { flag.StringVar(&config, "c", "", "choose config file.") flag.Parse() if config == "" { // 优先级: 命令行 > 环境变量 > 默认值 - if configEnv := os.Getenv(global.GVA_CONFIG.System.ConfigEnv); configEnv == "" { - config = defaultConfigFile - fmt.Printf("您正在使用config的默认值,config的路径为%v\n", defaultConfigFile) + if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" { + config = utils.ConfigFile + fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile) } else { config = configEnv fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config) diff --git a/server/utils/constant.go b/server/utils/constant.go new file mode 100644 index 00000000..bb50e80c --- /dev/null +++ b/server/utils/constant.go @@ -0,0 +1,6 @@ +package utils + +const ( + ConfigEnv = "GVA_CONFIG" + ConfigFile = "config.yaml" +)