Skip to content

Commit 6c4b217

Browse files
committed
repair config env error
1 parent 5b1eb54 commit 6c4b217

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

server/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ system:
4242
addr: 8888
4343
db-type: 'mysql'
4444
oss-type: 'local'
45-
config-env: 'GVA_CONFIG'
4645
need-init-data: false
4746
use-multipoint: false
4847

server/config/system.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type System struct {
55
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"`
66
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"`
77
OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"`
8-
ConfigEnv string `mapstructure:"config-env" json:"configEnv" yaml:"config-env"`
98
NeedInitData bool `mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"`
109
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"`
1110
}

server/core/config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ import (
55
"fmt"
66
"gin-vue-admin/global"
77
_ "gin-vue-admin/packfile"
8+
"gin-vue-admin/utils"
89
"github.com/fsnotify/fsnotify"
910
"github.com/spf13/viper"
1011
"os"
1112
)
1213

1314
var config string
1415

15-
const defaultConfigFile = "config.yaml"
16-
1716
func init() {
1817
flag.StringVar(&config, "c", "", "choose config file.")
1918
flag.Parse()
2019
if config == "" { // 优先级: 命令行 > 环境变量 > 默认值
21-
if configEnv := os.Getenv(global.GVA_CONFIG.System.ConfigEnv); configEnv == "" {
22-
config = defaultConfigFile
23-
fmt.Printf("您正在使用config的默认值,config的路径为%v\n", defaultConfigFile)
20+
if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" {
21+
config = utils.ConfigFile
22+
fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile)
2423
} else {
2524
config = configEnv
2625
fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config)

server/utils/constant.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package utils
2+
3+
const (
4+
ConfigEnv = "GVA_CONFIG"
5+
ConfigFile = "config.yaml"
6+
)

0 commit comments

Comments
 (0)