Browse Source

增加配置文件

kobe6258 7 months ago
parent
commit
e79890a288
4 changed files with 19 additions and 14 deletions
  1. 0 14
      common/component/component.go
  2. 16 0
      common/component/config/config.go
  3. 1 0
      go.mod
  4. 2 0
      go.sum

+ 0 - 14
common/component/component.go

@@ -7,23 +7,9 @@ import (
 	_ "eta/eta_mini_ht_api/common/component/sms"
 	"eta/eta_mini_ht_api/common/contants"
 	"eta/eta_mini_ht_api/common/utils/sms"
-	"fmt"
-	"github.com/beego/beego/v2/server/web"
-	"log"
 )
 
 func init() {
-	tmpRunMode, err := web.AppConfig.String("run_mode")
-	if err != nil {
-		panic(any("配置文件读取run_mode错误 " + err.Error()))
-	}
-	fmt.Println("RunMode:", tmpRunMode)
-	configPath := "/home/code/config/eta_mini_ht_api/conf/app.conf"
-	logger.Info("加载配置文件:%v", configPath)
-	err = web.LoadAppConfig("ini", configPath)
-	if err != nil {
-		log.Fatalf("web.LoadAppConfig Err:%v", err)
-	}
 	//配置SMS平台,没有配置直接报错
 	if smsConf, ok := config.GetConfig(contants.SMS).(*config.SMSConfig); ok && smsConf != nil {
 		logger.Info("开始加载短信平台客户端")

+ 16 - 0
common/component/config/config.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"github.com/beego/beego/v2/core/logs"
 	"github.com/beego/beego/v2/server/web"
+	"github.com/siddontang/go/log"
 )
 
 const (
@@ -56,3 +57,18 @@ func Register(name string, adapter Instance) {
 	}
 	configs[name] = adapter
 }
+
+func init() {
+	tmpRunMode, err := web.AppConfig.String("run_mode")
+	if err != nil {
+		panic(any("配置文件读取run_mode错误 " + err.Error()))
+	}
+	fmt.Println("RunMode:", tmpRunMode)
+	if tmpRunMode == "" {
+		configPath := "/home/code/config/eta_mini_ht_api/conf/app.conf"
+		err = web.LoadAppConfig("ini", configPath)
+		if err != nil {
+			log.Fatalf("web.LoadAppConfig Err:%v", err)
+		}
+	}
+}

+ 1 - 0
go.mod

@@ -9,6 +9,7 @@ require (
 	github.com/go-redis/redis/v8 v8.11.5
 	github.com/google/uuid v1.6.0
 	github.com/gorilla/websocket v1.5.3
+	github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0
 	github.com/silenceper/wechat/v2 v2.1.6
 	gorm.io/driver/mysql v1.5.7
 	gorm.io/gorm v1.25.11

+ 2 - 0
go.sum

@@ -104,6 +104,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
 github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
+github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0 h1:QIF48X1cihydXibm+4wfAc0r/qyPyuFiPFRNphdMpEE=
+github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
 github.com/silenceper/wechat/v2 v2.1.6 h1:2br2DxNzhksmvIBJ+PfMqjqsvoZmd/5BnMIfjKYUBgc=
 github.com/silenceper/wechat/v2 v2.1.6/go.mod h1:7Iu3EhQYVtDUJAj+ZVRy8yom75ga7aDWv8RurLkVm0s=
 github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=