Browse Source

修改项目

yjp 1 year ago
parent
commit
b93ba3e418

+ 3 - 3
project/gateway/api/root/example/example.go

@@ -1,12 +1,12 @@
 package example
 
 import (
+	"baize-demo/project/gateway/config"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 )
 
-const (
-	serviceBaseUrlNoPrefix = "http://localhost:31000"
-	serviceVersionedUrl    = serviceBaseUrlNoPrefix + "/example/api"
+var (
+	serviceVersionedUrl = config.GetConfig().ServicesConfig.ExampleBaseUrl + "/example/api"
 )
 
 func InitGateway(builder *gateway.Builder) {

+ 2 - 1
project/gateway/api/root/example/sql_executor.go

@@ -1,10 +1,11 @@
 package example
 
 import (
+	"baize-demo/project/gateway/config"
 	"git.sxidc.com/go-framework/baize/convenient/domain_gateway"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 )
 
 func sqlExecutorGateway(builder *gateway.Builder) {
-	domain_gateway.SqlExecutorGateway(serviceBaseUrlNoPrefix, builder)
+	domain_gateway.SqlExecutorGateway(config.GetConfig().ServicesConfig.ExampleBaseUrl, builder)
 }

+ 1 - 1
project/gateway/api/root/example/version.go

@@ -5,7 +5,7 @@ import (
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 )
 
-const (
+var (
 	versionBaseUrl = serviceVersionedUrl + "/version"
 )
 

+ 3 - 3
project/gateway/api/v1/example/example.go

@@ -1,12 +1,12 @@
 package example
 
 import (
+	"baize-demo/project/gateway/config"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 )
 
-const (
-	serviceBaseUrlNoPrefix = "http://localhost:31000"
-	serviceVersionedUrl    = serviceBaseUrlNoPrefix + "/example/api/v1"
+var (
+	serviceVersionedUrl = config.GetConfig().ServicesConfig.ExampleBaseUrl + "/example/api/v1"
 )
 
 func InitGateway(builder *gateway.Builder) {

+ 22 - 0
project/gateway/config/config.go

@@ -6,11 +6,18 @@ import (
 	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/service-supports/fslog"
 	"git.sxidc.com/service-supports/scm-sdk"
+	"gopkg.in/yaml.v3"
 	"os"
 )
 
 type Config struct {
 	ApplicationConfig application.Config
+	ServicesConfig    ServicesConfig `yaml:"services"`
+}
+
+type ServicesConfig struct {
+	TimeoutSec     int64  `yaml:"timeout_sec"`
+	ExampleBaseUrl string `yaml:"example_base_url"`
 }
 
 var conf Config
@@ -46,6 +53,11 @@ func initConfigFromSCM() {
 
 	conf.ApplicationConfig = applicationConfig
 
+	err = yaml.Unmarshal([]byte(info.Content), &conf)
+	if err != nil {
+		panic(err)
+	}
+
 	fslog.Info("Load config from scm finish")
 }
 
@@ -58,6 +70,16 @@ func initConfigFromConfigFile() {
 
 	conf.ApplicationConfig = applicationConfig
 
+	yamlBytes, err := os.ReadFile(configFilePath)
+	if err != nil {
+		panic(err)
+	}
+
+	err = yaml.Unmarshal(yamlBytes, &conf)
+	if err != nil {
+		panic(err)
+	}
+
 	fmt.Println("Load config file finish")
 }
 

+ 3 - 0
project/gateway/deployment/config/config.yaml

@@ -1,3 +1,6 @@
 api:
   url_prefix: /gateway/api
   port: 32000
+services:
+  timeoutSec: 30
+  example_base_url: http://localhost:31000