Browse Source

repair config env error

SliverHorn 4 years ago
parent
commit
8475853b31
4 changed files with 10 additions and 7 deletions
  1. 0 1
      server/config.yaml
  2. 0 1
      server/config/system.go
  3. 4 5
      server/core/config.go
  4. 6 0
      server/utils/constant.go

+ 0 - 1
server/config.yaml

@@ -42,7 +42,6 @@ system:
   addr: 8888
   db-type: 'mysql'
   oss-type: 'local'
-  config-env: 'GVA_CONFIG'
   need-init-data: false
   use-multipoint: false
 

+ 0 - 1
server/config/system.go

@@ -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"`
 }

+ 4 - 5
server/core/config.go

@@ -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)

+ 6 - 0
server/utils/constant.go

@@ -0,0 +1,6 @@
+package utils
+
+const (
+	ConfigEnv = "GVA_CONFIG"
+	ConfigFile = "config.yaml"
+)