Browse Source

添加校验

yjp 1 year ago
parent
commit
18e9ab2e5a
1 changed files with 20 additions and 0 deletions
  1. 20 0
      sdk/instance.go

+ 20 - 0
sdk/instance.go

@@ -1,6 +1,7 @@
 package sdk
 
 import (
+	"errors"
 	"git.sxidc.com/service-supports/ds-sdk/client"
 	"git.sxidc.com/service-supports/ds-sdk/grpc_client"
 )
@@ -30,6 +31,25 @@ func InitInstance(token string, address string, httpPort string, grpcPort string
 
 	c := client.New(options.timeout)
 
+	namespaceInfos, err := c.GetNamespaces(options.token, options.baseUrl, options.namespace, 1, 1)
+	if err != nil {
+		return err
+	}
+
+	if namespaceInfos == nil || len(namespaceInfos) == 0 {
+		return errors.New("命名空间不存在")
+	}
+
+	dataSourceInfos, err := c.GetDataSources(
+		options.token, options.baseUrl, options.namespace, options.dataSource, "", 1, 1)
+	if err != nil {
+		return err
+	}
+
+	if dataSourceInfos == nil || len(dataSourceInfos) == 0 {
+		return errors.New("数据源不存在")
+	}
+
 	grpcClient, err := grpc_client.NewClient(options.grpcAddress)
 	if err != nil {
 		return err