提交 8475853b 编写于 作者: Sliver_Horn's avatar Sliver_Horn

repair config env error

上级 350be998
......@@ -42,7 +42,6 @@ system:
addr: 8888
db-type: 'mysql'
oss-type: 'local'
config-env: 'GVA_CONFIG'
need-init-data: false
use-multipoint: false
......
......@@ -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"`
}
......@@ -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)
......
package utils
const (
ConfigEnv = "GVA_CONFIG"
ConfigFile = "config.yaml"
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册