Skip to content

Commit

Permalink
[Fix: http client supports namespaceId.] (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzeping.ricco committed Nov 18, 2024
1 parent 86a69b9 commit 128a1e9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions clients/http_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func RegisterMetaData(adminTokenData model.AdminTokenData, metaData *model.MetaD
params["contextPath"] = metaData.ContextPath
params["host"] = metaData.Host
params["port"] = metaData.Port
params["namespaceId"] = metaData.NamespaceId

if metaData.RPCType != "" {
params["rpcType"] = metaData.RPCType
Expand Down Expand Up @@ -107,6 +108,7 @@ func UrlRegister(adminTokenData model.AdminTokenData, urlMetaData *model.URIRegi
params["host"] = urlMetaData.Host
params["port"] = urlMetaData.Port
params["rpcType"] = urlMetaData.RPCType
params["namespaceId"] = urlMetaData.NamespaceId

tokenRequest := initShenYuCommonRequest(headers, params, constants.REGISTER_URI, "")

Expand Down
8 changes: 4 additions & 4 deletions docker-compose-consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version: "3.1"

services:
consul1:
image: consul:latest
image: consul:1.13.9
container_name: consul1
restart: always
networks:
Expand All @@ -28,7 +28,7 @@ services:
- ./data/consul/consul1/config:/consul/config

consul2:
image: consul:latest
image: consul:1.13.9
container_name: consul2
restart: always
networks:
Expand All @@ -39,7 +39,7 @@ services:
- ./data/consul/consul2/config:/consul/config

consul3:
image: consul:latest
image: consul:1.13.9
container_name: consul3
restart: always
networks:
Expand All @@ -50,7 +50,7 @@ services:
- ./data/consul/consul3/config:/consul/config

consul4:
image: consul:latest
image: consul:1.13.9
container_name: consul4
restart: always
ports:
Expand Down
36 changes: 19 additions & 17 deletions example/http_client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
NamespaceId: "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
NamespaceId: "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
}
1 change: 1 addition & 0 deletions model/common_meta_data_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ type MetaDataRegister struct {
PluginNames []interface{} `json:"pluginNames"`
RegisterMetaData bool `json:"registerMetaData"`
TimeMillis int64 `json:"timeMillis"`
NamespaceId string `json:"namespaceId"`
}
1 change: 1 addition & 0 deletions model/http_url_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ type URIRegister struct {
RPCType string `json:"rpcType"`
Host string `json:"host"`
Port string `json:"port"`
NamespaceId string `json:"namespaceId"`
}

0 comments on commit 128a1e9

Please sign in to comment.