Skip to content

Commit

Permalink
repair config env error
Browse files Browse the repository at this point in the history
  • Loading branch information
SliverHorn committed Oct 15, 2020
1 parent 350be99 commit 8475853
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ system:
addr: 8888
db-type: 'mysql'
oss-type: 'local'
config-env: 'GVA_CONFIG'
need-init-data: false
use-multipoint: false

Expand Down
1 change: 0 additions & 1 deletion server/config/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
9 changes: 4 additions & 5 deletions server/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ import (
"fmt"
"gin-vue-admin/global"
_ "gin-vue-admin/packfile"
"gin-vue-admin/utils"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"os"
)

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)
Expand Down
6 changes: 6 additions & 0 deletions server/utils/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package utils

const (
ConfigEnv = "GVA_CONFIG"
ConfigFile = "config.yaml"
)

0 comments on commit 8475853

Please sign in to comment.