maplepie
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
15 additions and
1 deletions
-
server/core/config.go
|
|
@ -6,13 +6,27 @@ import ( |
|
|
|
_ "gin-vue-admin/packfile" |
|
|
|
"github.com/fsnotify/fsnotify" |
|
|
|
"github.com/spf13/viper" |
|
|
|
"github.com/spf13/pflag" |
|
|
|
) |
|
|
|
|
|
|
|
const defaultConfigFile = "config.yaml" |
|
|
|
|
|
|
|
func init() { |
|
|
|
pflag.StringP("configFile","c", "", "choose config file.") |
|
|
|
pflag.Parse() |
|
|
|
|
|
|
|
// 优先级: 命令行 > 环境变量 > 默认值
|
|
|
|
v := viper.New() |
|
|
|
v.SetConfigFile(defaultConfigFile) |
|
|
|
v.BindPFlags(pflag.CommandLine) |
|
|
|
v.SetEnvPrefix("gva") |
|
|
|
v.BindEnv("configFile") // GVA_CONFIGFILE
|
|
|
|
|
|
|
|
configFile := v.GetString("configFile") |
|
|
|
if configFile == ""{ |
|
|
|
configFile = defaultConfigFile |
|
|
|
} |
|
|
|
|
|
|
|
v.SetConfigFile(configFile) |
|
|
|
err := v.ReadInConfig() |
|
|
|
if err != nil { |
|
|
|
panic(fmt.Errorf("Fatal error config file: %s \n", err)) |
|
|
|