diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69e4992..0e38c4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,6 +51,11 @@ jobs: - name: Check out code uses: actions/checkout@v1 + - name: Install docker-compose + run: | + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + - name: Start Zookeeper Docker Compose run: docker-compose -f docker-compose-zk.yml up -d diff --git a/clients/http_client_factory.go b/clients/http_client_factory.go index 038f21e..6e2f269 100644 --- a/clients/http_client_factory.go +++ b/clients/http_client_factory.go @@ -24,6 +24,7 @@ import ( "github.com/apache/shenyu-client-golang/common/shenyu_error" "github.com/apache/shenyu-client-golang/model" "reflect" + "strings" ) /** @@ -57,65 +58,80 @@ func NewShenYuAdminClient(client *model.ShenYuAdminClient) (adminToken model.Adm * Register metadata to ShenYu Gateway **/ func RegisterMetaData(adminTokenData model.AdminTokenData, metaData *model.MetaDataRegister) (registerResult bool, err error) { - headers := adapterHeaders(adminTokenData) - params := map[string]string{} - if metaData.AppName == "" || metaData.Path == "" || metaData.Host == "" || metaData.Port == "" { + if metaData.AppName == "" || metaData.Path == "" || metaData.Host == "" || metaData.Port == "" || metaData.NamespaceIds == "" { return false, shenyu_error.NewShenYuError(constants.MISS_PARAM_ERROR_CODE, constants.MISS_PARAM_ERROR_MSG, err) } - params["appName"] = metaData.AppName - params["path"] = metaData.Path - params["contextPath"] = metaData.ContextPath - params["host"] = metaData.Host - params["port"] = metaData.Port - - if metaData.RPCType != "" { - params["rpcType"] = metaData.RPCType - } else { - params["rpcType"] = constants.RPCTYPE_HTTP - } - if metaData.RuleName != "" { - params["ruleName"] = metaData.RuleName - } else { - params["ruleName"] = metaData.Path - } - - tokenRequest := initShenYuCommonRequest(headers, params, constants.REGISTER_METADATA, "") - - registerResult, err = http_client.RegisterMetaData(tokenRequest) - if err == nil { - return registerResult, nil - } else { - return false, err + namespaceIds := strings.Split(metaData.NamespaceIds, ";") + + for _, namespaceId := range namespaceIds { + if namespaceId == "" { + continue + } + params := map[string]string{} + params["appName"] = metaData.AppName + params["path"] = metaData.Path + params["contextPath"] = metaData.ContextPath + params["host"] = metaData.Host + params["port"] = metaData.Port + params["namespaceId"] = namespaceId + + if metaData.RPCType != "" { + params["rpcType"] = metaData.RPCType + } else { + params["rpcType"] = constants.RPCTYPE_HTTP + } + + if metaData.RuleName != "" { + params["ruleName"] = metaData.RuleName + } else { + params["ruleName"] = metaData.Path + } + headers := adapterHeaders(adminTokenData) + tokenRequest := initShenYuCommonRequest(headers, params, constants.REGISTER_METADATA, "") + + _, err = http_client.RegisterMetaData(tokenRequest) + if err != nil { + return false, err + } } + return true, nil } /** * Url Register to ShenYu Gateway **/ func UrlRegister(adminTokenData model.AdminTokenData, urlMetaData *model.URIRegister) (registerResult bool, err error) { - headers := adapterHeaders(adminTokenData) - params := map[string]string{} - if urlMetaData.AppName == "" || urlMetaData.RPCType == "" || urlMetaData.Host == "" || urlMetaData.Port == "" { + if urlMetaData.AppName == "" || urlMetaData.RPCType == "" || urlMetaData.Host == "" || urlMetaData.Port == "" || urlMetaData.NamespaceIds == "" { return false, shenyu_error.NewShenYuError(constants.MISS_PARAM_ERROR_CODE, constants.MISS_PARAM_ERROR_MSG, err) } - params["protocol"] = urlMetaData.Protocol - params["appName"] = urlMetaData.AppName - params["contextPath"] = urlMetaData.ContextPath - params["host"] = urlMetaData.Host - params["port"] = urlMetaData.Port - params["rpcType"] = urlMetaData.RPCType - tokenRequest := initShenYuCommonRequest(headers, params, constants.REGISTER_URI, "") - - registerResult, err = http_client.DoUrlRegister(tokenRequest) - if err == nil { - return registerResult, nil - } else { - return false, err + namespaceIds := strings.Split(urlMetaData.NamespaceIds, ";") + + for _, namespaceId := range namespaceIds { + if namespaceId == "" { + continue + } + params := map[string]string{} + params["protocol"] = urlMetaData.Protocol + params["appName"] = urlMetaData.AppName + params["contextPath"] = urlMetaData.ContextPath + params["host"] = urlMetaData.Host + params["port"] = urlMetaData.Port + params["rpcType"] = urlMetaData.RPCType + params["namespaceId"] = namespaceId + + headers := adapterHeaders(adminTokenData) + tokenRequest := initShenYuCommonRequest(headers, params, constants.REGISTER_URI, "") + + _, err = http_client.DoUrlRegister(tokenRequest) + if err != nil { + return false, err + } } + return true, nil } /** diff --git a/clients/nacos_client/nacos_client.go b/clients/nacos_client/nacos_client.go index bfd949f..f4b62dd 100644 --- a/clients/nacos_client/nacos_client.go +++ b/clients/nacos_client/nacos_client.go @@ -42,7 +42,7 @@ type ShenYuNacosClient struct { type NacosClientParam struct { IpAddr string //the nacos server address require user provide Port uint64 //the nacos server port require user provide - NamespaceId string // the namespaceId of Nacos.When namespace is public, fill in the blank string here require user provide. + NamespaceId string //the namespaceId of Nacos require user provide. } /** diff --git a/clients/zk_client/zk_client.go b/clients/zk_client/zk_client.go index 5eb3ce4..69a3c16 100644 --- a/clients/zk_client/zk_client.go +++ b/clients/zk_client/zk_client.go @@ -90,6 +90,12 @@ func (zc *ShenYuZkClient) DeregisterServiceInstance(metaData interface{}) (deReg if err != nil { return false, err } + if len(childs) == 0 { + err := zc.ZkClient.Delete(path, stat.Version) + if err != nil { + return false, err + } + } for _, child := range childs { fullPath := path + "/" + child err := zc.ZkClient.Delete(fullPath, stat.Version) diff --git a/docker-compose-consul.yml b/docker-compose-consul.yml index 1e1230a..d61f80e 100644 --- a/docker-compose-consul.yml +++ b/docker-compose-consul.yml @@ -17,7 +17,7 @@ version: "3.1" services: consul1: - image: consul:latest + image: consul:1.15.4 container_name: consul1 restart: always networks: @@ -28,35 +28,43 @@ services: - ./data/consul/consul1/config:/consul/config consul2: - image: consul:latest + image: consul:1.15.4 container_name: consul2 restart: always networks: - shenyu + depends_on: + - consul1 command: agent -server -client=0.0.0.0 -bind 0.0.0.0 -retry-join=consul1 -node=consul2 volumes: - ./data/consul/consul2/data:/consul/data - ./data/consul/consul2/config:/consul/config consul3: - image: consul:latest + image: consul:1.15.4 container_name: consul3 restart: always networks: - shenyu + depends_on: + - consul1 command: agent -server -client=0.0.0.0 -bind 0.0.0.0 -retry-join=consul1 -node=consul3 volumes: - ./data/consul/consul3/data:/consul/data - ./data/consul/consul3/config:/consul/config consul4: - image: consul:latest + image: consul:1.15.4 container_name: consul4 restart: always ports: - 8500:8500 networks: - shenyu + depends_on: + - consul1 + - consul2 + - consul3 command: agent -client=0.0.0.0 -bind 0.0.0.0 -retry-join=consul1 -ui -node=client1 volumes: - ./data/consul/consul4/data:/consul/data diff --git a/example/consul_client/consul_client.go b/example/consul_client/consul_client.go index e6512a0..b705123 100644 --- a/example/consul_client/consul_client.go +++ b/example/consul_client/consul_client.go @@ -55,36 +55,39 @@ func main() { metaData1 := &model.ConsulMetaDataRegister{ ServiceId: uuid1, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "/your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "/your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData2 := &model.ConsulMetaDataRegister{ ServiceId: uuid2, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "/your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "/your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData3 := &model.ConsulMetaDataRegister{ ServiceId: uuid3, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "/your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "/your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } diff --git a/example/consul_client/consul_client_test.go b/example/consul_client/consul_client_test.go index 15227e7..e9575e5 100644 --- a/example/consul_client/consul_client_test.go +++ b/example/consul_client/consul_client_test.go @@ -73,36 +73,39 @@ func TestRegisterServiceInstance(t *testing.T) { metaData1 := &model.ConsulMetaDataRegister{ ServiceId: uuid1, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "/your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "/your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData2 := &model.ConsulMetaDataRegister{ ServiceId: uuid2, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "/your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "/your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData3 := &model.ConsulMetaDataRegister{ ServiceId: uuid3, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "/your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "/your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } @@ -147,36 +150,39 @@ func TestDeregisterServiceInstance(t *testing.T) { metaData1 := &model.ConsulMetaDataRegister{ ServiceId: uuid1, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "/your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "/your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData2 := &model.ConsulMetaDataRegister{ ServiceId: uuid2, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "/your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "/your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData3 := &model.ConsulMetaDataRegister{ ServiceId: uuid3, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "/your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "/your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } @@ -237,36 +243,39 @@ func TestGetServiceInstanceInfo(t *testing.T) { metaData1 := &model.ConsulMetaDataRegister{ ServiceId: uuid1, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "/your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "/your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData2 := &model.ConsulMetaDataRegister{ ServiceId: uuid2, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "/your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "/your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData3 := &model.ConsulMetaDataRegister{ ServiceId: uuid3, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "/your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide - RPCType: "http", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "/your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } @@ -333,36 +342,39 @@ func TestEntireConsulFunction(t *testing.T) { metaData1 := &model.ConsulMetaDataRegister{ ServiceId: uuid1, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testEntireMetaDataRegister1", //require user provide - Path: "/your/entire/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide - RPCType: "http", //require user provide + AppName: "testEntireMetaDataRegister1", //require user provide + Path: "/your/entire/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData2 := &model.ConsulMetaDataRegister{ ServiceId: uuid2, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testEntireMetaDataRegister2", //require user provide - Path: "/your/entire/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide - RPCType: "http", //require user provide + AppName: "testEntireMetaDataRegister2", //require user provide + Path: "/your/entire/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } metaData3 := &model.ConsulMetaDataRegister{ ServiceId: uuid3, ShenYuMetaData: &model.MetaDataRegister{ - AppName: "testEntireMetaDataRegister3", //require user provide - Path: "/your/entire/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide - RPCType: "http", //require user provide + AppName: "testEntireMetaDataRegister3", //require user provide + Path: "/your/entire/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + RPCType: "http", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide }, } diff --git a/example/etcd_client/etcd_client.go b/example/etcd_client/etcd_client.go index d640d55..3482d1d 100644 --- a/example/etcd_client/etcd_client.go +++ b/example/etcd_client/etcd_client.go @@ -44,19 +44,21 @@ func main() { //init MetaDataRegister metaData1 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData2 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } //register multiple metaData diff --git a/example/etcd_client/etcd_client_test.go b/example/etcd_client/etcd_client_test.go index 07c595e..5735fc5 100644 --- a/example/etcd_client/etcd_client_test.go +++ b/example/etcd_client/etcd_client_test.go @@ -33,7 +33,7 @@ import ( func TestInitEtcdClient(t *testing.T) { ecp := &etcd_client.EtcdClientParam{ EtcdServers: []string{"http://127.0.0.1:2379"}, //require user provide - TTL: 50, + TTL: 50, } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.ETCD_CLIENT) @@ -52,7 +52,7 @@ func TestInitEtcdClient(t *testing.T) { func TestRegisterServiceInstanceAndGetServiceInstanceInfo(t *testing.T) { ecp := &etcd_client.EtcdClientParam{ EtcdServers: []string{"http://127.0.0.1:2379"}, //require user provide - TTL: 50, + TTL: 50, } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.ETCD_CLIENT) @@ -67,22 +67,23 @@ func TestRegisterServiceInstanceAndGetServiceInstanceInfo(t *testing.T) { //init MetaDataRegister metaData1 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData2 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } - //register multiple metaData registerResult1, err := etcd.RegisterServiceInstance(metaData1) assert.Nil(t, err) @@ -92,7 +93,6 @@ func TestRegisterServiceInstanceAndGetServiceInstanceInfo(t *testing.T) { assert.Nil(t, err) assert.True(t, registerResult2) - time.Sleep(time.Second) instanceDetail, err := etcd.GetServiceInstanceInfo(metaData1) @@ -111,7 +111,7 @@ func TestRegisterServiceInstanceAndGetServiceInstanceInfo(t *testing.T) { func TestDeRegisterServiceInstance(t *testing.T) { ecp := &etcd_client.EtcdClientParam{ EtcdServers: []string{"http://127.0.0.1:2379"}, //require user provide - TTL: 50, + TTL: 50, } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.ETCD_CLIENT) @@ -126,22 +126,23 @@ func TestDeRegisterServiceInstance(t *testing.T) { //init MetaDataRegister metaData1 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData2 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } - //register multiple metaData registerResult1, err := etcd.DeregisterServiceInstance(metaData1) assert.Nil(t, err) @@ -151,5 +152,3 @@ func TestDeRegisterServiceInstance(t *testing.T) { assert.Nil(t, err) assert.True(t, registerResult2) } - - diff --git a/example/http_client/http_client.go b/example/http_client/http_client.go index 696c786..c216caa 100644 --- a/example/http_client/http_client.go +++ b/example/http_client/http_client.go @@ -37,38 +37,40 @@ func main() { adminToken, err := clients.NewShenYuAdminClient(adminClient) if err == nil { - fmt.Printf("this is ShenYu Admin client token %v ->", adminToken.AdminTokenData.Token) + fmt.Printf("this is ShenYu Admin client token: %v\n", adminToken.AdminTokenData.Token) } //init MetaDataRegister metaData := &model.MetaDataRegister{ - AppName: "testGoAppName", //require user provide - Path: "/golang/your/path", //require user provide - ContextPath: "/golang", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testGoAppName", //require user provide + Path: "/golang/your/path", //require user provide + ContextPath: "/golang", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } result, err := clients.RegisterMetaData(adminToken.AdminTokenData, metaData) if err != nil { - fmt.Printf("MetaDataRegister has error %v:", err) + fmt.Printf("MetaDataRegister has error: %v\n", err) } - fmt.Printf("finish register metadata ,the result is %v ->", result) + fmt.Printf("finish register metadata ,the result is: %v\n", result) //init urlRegister urlRegister := &model.URIRegister{ - Protocol: "http://", //require user provide - AppName: "testGoAppName", //require user provide - ContextPath: "/golang", //require user provide - RPCType: constants.RPCTYPE_HTTP, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + Protocol: "http://", //require user provide + AppName: "testGoAppName", //require user provide + ContextPath: "/golang", //require user provide + RPCType: constants.RPCTYPE_HTTP, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } result, err = clients.UrlRegister(adminToken.AdminTokenData, urlRegister) if err != nil { - fmt.Printf("UrlRegister has error %v:", err) + fmt.Printf("UrlRegister has error: %v\n", err) } - fmt.Printf("finish UrlRegister ,the result is %v ->", result) + fmt.Printf("finish UrlRegister ,the result is: %v\n", result) //do you logic } diff --git a/example/nacos_client/nacos_client.go b/example/nacos_client/nacos_client.go index fd94179..a19e1be 100644 --- a/example/nacos_client/nacos_client.go +++ b/example/nacos_client/nacos_client.go @@ -39,7 +39,7 @@ func main() { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -56,12 +56,13 @@ func main() { //RegisterServiceInstance start //metaData is necessary param, this will be register to shenyu gateway to use metaData := &model.URIRegister{ - Protocol: "testMetaDataRegister", //require user provide - AppName: "testURLRegister", //require user provide - ContextPath: "contextPath", //require user provide - RPCType: constants.RPCTYPE_HTTP, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + Protocol: "testMetaDataRegister", //require user provide + AppName: "testURLRegister", //require user provide + ContextPath: "contextPath", //require user provide + RPCType: constants.RPCTYPE_HTTP, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaDataStringJson, _ := json.Marshal(metaData) diff --git a/example/nacos_client/nacos_client_test.go b/example/nacos_client/nacos_client_test.go index 8ac2c9a..6fb37ca 100644 --- a/example/nacos_client/nacos_client_test.go +++ b/example/nacos_client/nacos_client_test.go @@ -38,7 +38,7 @@ func TestInitNacosClient(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -57,7 +57,7 @@ func TestInitNacosClientAndRegister(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -73,12 +73,13 @@ func TestInitNacosClientAndRegister(t *testing.T) { //metaData is necessary param, this will be register to shenyu gateway to use metaData := &model.URIRegister{ - Protocol: "testMetaDataRegister", //require user provide - AppName: "testURLRegister", //require user provide - ContextPath: "contextPath", //require user provide - RPCType: constants.RPCTYPE_HTTP, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + Protocol: "testMetaDataRegister", //require user provide + AppName: "testURLRegister", //require user provide + ContextPath: "contextPath", //require user provide + RPCType: constants.RPCTYPE_HTTP, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaDataStringJson, _ := json.Marshal(metaData) @@ -107,7 +108,7 @@ func TestRegisterAndGetInstance(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -123,12 +124,13 @@ func TestRegisterAndGetInstance(t *testing.T) { //metaData is necessary param, this will be register to shenyu gateway to use metaData := &model.URIRegister{ - Protocol: "testMetaDataRegister", //require user provide - AppName: "testURLRegister", //require user provide - ContextPath: "contextPath", //require user provide - RPCType: constants.RPCTYPE_HTTP, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + Protocol: "testMetaDataRegister", //require user provide + AppName: "testURLRegister", //require user provide + ContextPath: "contextPath", //require user provide + RPCType: constants.RPCTYPE_HTTP, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaDataStringJson, _ := json.Marshal(metaData) @@ -171,7 +173,7 @@ func TestRegisterAndDeregister(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -187,12 +189,13 @@ func TestRegisterAndDeregister(t *testing.T) { //metaData is necessary param, this will be register to shenyu gateway to use metaData := &model.URIRegister{ - Protocol: "testMetaDataRegister", //require user provide - AppName: "testURLRegister", //require user provide - ContextPath: "contextPath", //require user provide - RPCType: constants.RPCTYPE_HTTP, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + Protocol: "testMetaDataRegister", //require user provide + AppName: "testURLRegister", //require user provide + ContextPath: "contextPath", //require user provide + RPCType: constants.RPCTYPE_HTTP, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaDataStringJson, _ := json.Marshal(metaData) diff --git a/example/zk_client/zk_client.go b/example/zk_client/zk_client.go index 513125b..36673fe 100644 --- a/example/zk_client/zk_client.go +++ b/example/zk_client/zk_client.go @@ -49,27 +49,30 @@ func main() { //RegisterServiceInstance start //init MetaDataRegister metaData1 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData2 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData3 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } //register multiple metaData diff --git a/example/zk_client/zk_client_test.go b/example/zk_client/zk_client_test.go index 4dbcfb9..477e06f 100644 --- a/example/zk_client/zk_client_test.go +++ b/example/zk_client/zk_client_test.go @@ -67,27 +67,30 @@ func TestRegisterServiceInstanceAndGetServiceInstanceInfo(t *testing.T) { //init MetaDataRegister metaData1 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData2 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData3 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } //register multiple metaData @@ -139,27 +142,30 @@ func TestDeregisterServiceInstance(t *testing.T) { //init MetaDataRegister metaData1 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister1", //require user provide - Path: "your/path1", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8080", //require user provide + AppName: "testMetaDataRegister1", //require user provide + Path: "your/path1", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8080", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData2 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister2", //require user provide - Path: "your/path2", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8181", //require user provide + AppName: "testMetaDataRegister2", //require user provide + Path: "your/path2", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8181", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } metaData3 := &model.MetaDataRegister{ - AppName: "testMetaDataRegister3", //require user provide - Path: "your/path3", //require user provide - Enabled: true, //require user provide - Host: "127.0.0.1", //require user provide - Port: "8282", //require user provide + AppName: "testMetaDataRegister3", //require user provide + Path: "your/path3", //require user provide + Enabled: true, //require user provide + Host: "127.0.0.1", //require user provide + Port: "8282", //require user provide + NamespaceIds: "649330b6-c2d7-4edc-be8e-8a54df9eb385", //require user provide } deRegisterResult1, err := zc.DeregisterServiceInstance(metaData1) diff --git a/model/common_meta_data_register.go b/model/common_meta_data_register.go index 8721e7d..78f0ce1 100644 --- a/model/common_meta_data_register.go +++ b/model/common_meta_data_register.go @@ -32,4 +32,5 @@ type MetaDataRegister struct { PluginNames []interface{} `json:"pluginNames"` RegisterMetaData bool `json:"registerMetaData"` TimeMillis int64 `json:"timeMillis"` + NamespaceIds string `json:"namespaceIds"` // Support multiple ns, split by ";" } diff --git a/model/http_url_register.go b/model/http_url_register.go index 712fe95..fe32926 100644 --- a/model/http_url_register.go +++ b/model/http_url_register.go @@ -21,10 +21,11 @@ package model * The ShenYu Http URIRegister **/ type URIRegister struct { - Protocol string `json:"protocol"` - AppName string `json:"appName"` - ContextPath string `json:"contextPath"` - RPCType string `json:"rpcType"` - Host string `json:"host"` - Port string `json:"port"` + Protocol string `json:"protocol"` + AppName string `json:"appName"` + ContextPath string `json:"contextPath"` + RPCType string `json:"rpcType"` + Host string `json:"host"` + Port string `json:"port"` + NamespaceIds string `json:"namespaceIds"` // Support multiple ns, split by ";" }