Browse Source

修改配置

yjp 11 months ago
parent
commit
f43e414118

+ 7 - 6
baize.go

@@ -39,12 +39,13 @@ func NewApplication(conf application.Config) *application.App {
 		dataServiceConfig := conf.InfrastructureConfig.Database.DataService
 		if dataServiceConfig != nil {
 			infrastructureConfig.DatabaseConfig.DataService = &data_service.Config{
-				Token:       dataServiceConfig.Token,
-				BaseUrl:     dataServiceConfig.BaseUrl,
-				GrpcAddress: dataServiceConfig.GrpcAddress,
-				Namespace:   dataServiceConfig.Namespace,
-				DataSource:  dataServiceConfig.DataSource,
-				TimeoutSec:  dataServiceConfig.TimeoutSec,
+				Token:      dataServiceConfig.Token,
+				Address:    dataServiceConfig.Address,
+				HttpPort:   dataServiceConfig.HttpPort,
+				GrpcPort:   dataServiceConfig.GrpcPort,
+				Namespace:  dataServiceConfig.Namespace,
+				DataSource: dataServiceConfig.DataSource,
+				TimeoutSec: dataServiceConfig.TimeoutSec,
 			}
 		}
 	}

+ 3 - 2
examples/examples/project/deployment/config/config.yaml

@@ -13,8 +13,9 @@ infrastructure:
       max_idle_connections: 5
 #    data_service:
 #      token: "8qe+uPgpQ2JWxu3lSyOx5NjX+INp5WsnoD1ZWb7PBm4="
-#      base_url: http://localhost:10000
-#      grpc_address: localhost:10001
+#      address: "localhost"
+#      http_port: "10000"
+#      grpc_port: "10001"
 #      namespace: "baize"
 #      data_source: "baize"
 #      timeout_sec: 30

+ 18 - 11
framwork/infrastructure/database/data_service/data_service.go

@@ -12,12 +12,13 @@ import (
 )
 
 type Config struct {
-	Token       string `json:"token" yaml:"token"`
-	BaseUrl     string `json:"base_url" yaml:"base_url"`
-	GrpcAddress string `json:"grpc_address" yaml:"grpc_address"`
-	Namespace   string `json:"namespace" yaml:"namespace"`
-	DataSource  string `json:"data_source" yaml:"data_source"`
-	TimeoutSec  int64  `json:"timeout_sec" yaml:"timeout_sec"`
+	Token      string `json:"token" yaml:"token"`
+	Address    string `json:"address" yaml:"address"`
+	HttpPort   string `json:"http_port" yaml:"http_port"`
+	GrpcPort   string `json:"grpc_port" yaml:"grpc_port"`
+	Namespace  string `json:"namespace" yaml:"namespace"`
+	DataSource string `json:"data_source" yaml:"data_source"`
+	TimeoutSec int64  `json:"timeout_sec" yaml:"timeout_sec"`
 }
 
 type DataService struct {
@@ -27,9 +28,13 @@ type DataService struct {
 }
 
 func NewDataService(config *Config) (*DataService, error) {
+	baseUrl := "http://" + config.Address + ":" + config.HttpPort
+	grpcAddress := config.Address + ":" + config.GrpcPort
+
 	c := client.New(time.Duration(config.TimeoutSec) * time.Second)
 
-	namespaceInfos, err := c.GetNamespaces(config.Token, config.BaseUrl, config.Namespace, 1, 1)
+	namespaceInfos, err := c.GetNamespaces(config.Token, baseUrl,
+		config.Namespace, 1, 1)
 	if err != nil {
 		return nil, err
 	}
@@ -39,7 +44,7 @@ func NewDataService(config *Config) (*DataService, error) {
 	}
 
 	dataSourceInfos, err := c.GetDataSources(
-		config.Token, config.BaseUrl, config.Namespace, config.DataSource, "", 1, 1)
+		config.Token, baseUrl, config.Namespace, config.DataSource, "", 1, 1)
 	if err != nil {
 		return nil, err
 	}
@@ -48,7 +53,7 @@ func NewDataService(config *Config) (*DataService, error) {
 		return nil, fserr.New("数据源不存在")
 	}
 
-	grpcClient, err := grpc_client.NewClient(config.GrpcAddress)
+	grpcClient, err := grpc_client.NewClient(grpcAddress)
 	if err != nil {
 		return nil, err
 	}
@@ -81,8 +86,9 @@ func (ds *DataService) ExecuteRawSql(sqlStr string, executeParams map[string]any
 	}
 
 	config := ds.config
+	baseUrl := "http://" + config.Address + ":" + config.HttpPort
 
-	tableRows, err := ds.client.ExecuteRawSql(config.Token, config.BaseUrl,
+	tableRows, err := ds.client.ExecuteRawSql(config.Token, baseUrl,
 		config.Namespace, config.DataSource, sqlStr, executeParams)
 	if err != nil {
 		return nil, err
@@ -102,8 +108,9 @@ func (ds *DataService) ExecuteSql(name string, executeParams map[string]any) ([]
 	}
 
 	config := ds.config
+	baseUrl := "http://" + config.Address + ":" + config.HttpPort
 
-	tableRows, err := ds.client.ExecuteSql(config.Token, config.BaseUrl,
+	tableRows, err := ds.client.ExecuteSql(config.Token, baseUrl,
 		config.Namespace, config.DataSource, name, executeParams)
 	if err != nil {
 		return nil, err