Skip to content

Commit af4152b

Browse files
add schema summary (#28)
1 parent ba78233 commit af4152b

File tree

5 files changed

+7125
-13
lines changed

5 files changed

+7125
-13
lines changed

client.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import (
1313
"sync"
1414
"time"
1515

16+
"crypto/sha256"
1617
"github.com/cenkalti/backoff"
1718
"github.com/go-chassis/go-chassis/pkg/httpclient"
19+
"github.com/go-chassis/go-sc-client/proto"
1820
"github.com/go-mesh/openlogging"
1921
"github.com/gorilla/websocket"
2022
)
@@ -270,10 +272,10 @@ func (c *RegistryClient) GetProviders(consumer string, opts ...CallOption) (*Mic
270272
providersURL := c.formatURL(fmt.Sprintf("%s%s/%s/providers", MSAPIPath, MicroservicePath, consumer), nil, copts)
271273
resp, err := c.HTTPDo("GET", providersURL, nil, nil)
272274
if err != nil {
273-
return nil, fmt.Errorf("Get Providers failed, error: %s, MicroServiceid: %s", err, consumer)
275+
return nil, fmt.Errorf("get Providers failed, error: %s, MicroServiceid: %s", err, consumer)
274276
}
275277
if resp == nil {
276-
return nil, fmt.Errorf("Get Providers failed, response is empty, MicroServiceid: %s", consumer)
278+
return nil, fmt.Errorf("get Providers failed, response is empty, MicroServiceid: %s", consumer)
277279
}
278280
var body []byte
279281
body, err = ioutil.ReadAll(resp.Body)
@@ -312,7 +314,7 @@ func (c *RegistryClient) AddDependencies(request *MircroServiceDependencyRequest
312314
return fmt.Errorf("AddDependencies failed, response is empty")
313315
}
314316
if resp.StatusCode != http.StatusOK {
315-
return NewCommonException("add microservice dependencies failed. response StatusCode: %d, response body: %s",
317+
return NewCommonException("add micro service dependencies failed. response StatusCode: %d, response body: %s",
316318
resp.StatusCode, string(body))
317319
}
318320
return nil
@@ -321,12 +323,20 @@ func (c *RegistryClient) AddDependencies(request *MircroServiceDependencyRequest
321323
// AddSchemas adds a schema contents to the services registered in service-center
322324
func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo string) error {
323325
if microServiceID == "" {
324-
return errors.New("invalid microserviceID")
326+
return errors.New("invalid micro service ID")
325327
}
326328

327329
schemaURL := c.formatURL(fmt.Sprintf("%s%s/%s%s/%s", MSAPIPath, MicroservicePath, microServiceID, SchemaPath, schemaName), nil, nil)
328-
request := &MicroServiceInstanceSchemaUpdateRequest{
329-
SchemaContent: schemaInfo,
330+
h := sha256.New()
331+
_, err := h.Write([]byte(schemaInfo))
332+
if err != nil {
333+
return err
334+
}
335+
request := &proto.ModifySchemaRequest{
336+
SchemaId: schemaName,
337+
ServiceId: microServiceID,
338+
Schema: schemaInfo,
339+
Summary: fmt.Sprintf("%x", h.Sum(nil)),
330340
}
331341
body, err := json.Marshal(request)
332342
if err != nil {
@@ -339,7 +349,7 @@ func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo strin
339349
}
340350

341351
if resp == nil {
342-
return fmt.Errorf("Addschemas failed, response is empty")
352+
return fmt.Errorf("add schemas failed, response is empty")
343353
}
344354

345355
if resp.StatusCode != http.StatusOK {

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ module github.com/go-chassis/go-sc-client
22

33
require (
44
github.com/cenkalti/backoff v2.0.0+incompatible
5-
github.com/go-chassis/go-chassis v1.1.0
5+
github.com/go-chassis/go-chassis v1.1.3
66
github.com/go-chassis/paas-lager v0.0.0-20181123014243-005283cca84c
77
github.com/go-mesh/openlogging v0.0.0-20181122085847-3daf3ad8ed35
8+
github.com/golang/protobuf v1.2.0
89
github.com/gorilla/websocket v1.4.0
910
github.com/stretchr/testify v1.2.2
11+
golang.org/x/net v0.0.0-20180824152047-4bcd98cce591
12+
google.golang.org/grpc v1.14.0
13+
1014
)

0 commit comments

Comments
 (0)