Skip to content

Commit e6e0f1d

Browse files
author
pixel
committed
Merge branch 'develop' of https://github.com/piexlmax/QMPlus into gva_gormv2_dev
2 parents d3dfdac + 225ef0f commit e6e0f1d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

server/core/config.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@ import (
66
_ "gin-vue-admin/packfile"
77
"github.com/fsnotify/fsnotify"
88
"github.com/spf13/viper"
9+
"github.com/spf13/pflag"
910
)
1011

1112
const defaultConfigFile = "config.yaml"
1213

1314
func init() {
15+
pflag.StringP("configFile","c", "", "choose config file.")
16+
pflag.Parse()
17+
18+
// 优先级: 命令行 > 环境变量 > 默认值
1419
v := viper.New()
15-
v.SetConfigFile(defaultConfigFile)
20+
v.BindPFlags(pflag.CommandLine)
21+
v.SetEnvPrefix("gva")
22+
v.BindEnv("configFile") // GVA_CONFIGFILE
23+
24+
configFile := v.GetString("configFile")
25+
if configFile == ""{
26+
configFile = defaultConfigFile
27+
}
28+
29+
v.SetConfigFile(configFile)
1630
err := v.ReadInConfig()
1731
if err != nil {
1832
panic(fmt.Errorf("Fatal error config file: %s \n", err))

0 commit comments

Comments
 (0)