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