|
1 | | -### Service-Center Client for Go-Chassis |
2 | | -[](https://travis-ci.org/go-chassis/go-sc-client) |
3 | | -This is a service-center client which helps the microservice to interact with Service-Center |
4 | | -for service-registration, discovery, instance registration and dependency management. |
| 1 | +# Service Center client for go |
| 2 | +This is a service center client which helps the microservice to interact with Service Center |
| 3 | +for service-registration, discovery, instance registration etc. |
5 | 4 |
|
6 | | -This client implements all the [api's](https://rawcdn.githack.com/go-chassis/service-center/master/docs/api-docs.html) of Service-Center. |
| 5 | +This client implements all the [api's](https://rawcdn.githack.com/go-chassis/service-center/master/docs/api-docs.html) of Service Center. |
7 | 6 |
|
8 | 7 |
|
| 8 | +# Usage |
9 | 9 |
|
10 | | -**NOTICE**: this client is migrate to github.com/go-chassis/go-chassis/pkg/scclient |
| 10 | +```go |
| 11 | +registryClient, err := sc.NewClient( |
| 12 | + sc.Options{ |
| 13 | + Addrs: []string{"127.0.0.1:30100"}, |
| 14 | + }) |
| 15 | +``` |
| 16 | +declare and register micro service |
| 17 | +```go |
| 18 | +var ms = new(discovery.MicroService) |
| 19 | +var m = make(map[string]string) |
| 20 | + |
| 21 | +m["abc"] = "abc" |
| 22 | +m["def"] = "def" |
| 23 | + |
| 24 | +ms.AppId = MSList[0].AppId |
| 25 | +ms.ServiceName = MSList[0].ServiceName |
| 26 | +ms.Version = MSList[0].Version |
| 27 | +ms.Environment = MSList[0].Environment |
| 28 | +ms.Properties = m |
| 29 | +sid, err := registryClient.RegisterService(ms) |
| 30 | +``` |
| 31 | +declare and register instance |
| 32 | +```go |
| 33 | + microServiceInstance := &discovery.MicroServiceInstance{ |
| 34 | + Endpoints: []string{"rest://127.0.0.1:3000"}, |
| 35 | + HostName: hostname, |
| 36 | + Status: sc.MSInstanceUP, |
| 37 | + } |
| 38 | + id, err := registryClient.RegisterMicroServiceInstance(microServiceInstance) |
| 39 | +``` |
0 commit comments