Skip to content

Commit

Permalink
add schema summary (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang authored Dec 28, 2018
1 parent ba78233 commit af4152b
Show file tree
Hide file tree
Showing 5 changed files with 7,125 additions and 13 deletions.
24 changes: 17 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"sync"
"time"

"crypto/sha256"
"github.com/cenkalti/backoff"
"github.com/go-chassis/go-chassis/pkg/httpclient"
"github.com/go-chassis/go-sc-client/proto"
"github.com/go-mesh/openlogging"
"github.com/gorilla/websocket"
)
Expand Down Expand Up @@ -270,10 +272,10 @@ func (c *RegistryClient) GetProviders(consumer string, opts ...CallOption) (*Mic
providersURL := c.formatURL(fmt.Sprintf("%s%s/%s/providers", MSAPIPath, MicroservicePath, consumer), nil, copts)
resp, err := c.HTTPDo("GET", providersURL, nil, nil)
if err != nil {
return nil, fmt.Errorf("Get Providers failed, error: %s, MicroServiceid: %s", err, consumer)
return nil, fmt.Errorf("get Providers failed, error: %s, MicroServiceid: %s", err, consumer)
}
if resp == nil {
return nil, fmt.Errorf("Get Providers failed, response is empty, MicroServiceid: %s", consumer)
return nil, fmt.Errorf("get Providers failed, response is empty, MicroServiceid: %s", consumer)
}
var body []byte
body, err = ioutil.ReadAll(resp.Body)
Expand Down Expand Up @@ -312,7 +314,7 @@ func (c *RegistryClient) AddDependencies(request *MircroServiceDependencyRequest
return fmt.Errorf("AddDependencies failed, response is empty")
}
if resp.StatusCode != http.StatusOK {
return NewCommonException("add microservice dependencies failed. response StatusCode: %d, response body: %s",
return NewCommonException("add micro service dependencies failed. response StatusCode: %d, response body: %s",
resp.StatusCode, string(body))
}
return nil
Expand All @@ -321,12 +323,20 @@ func (c *RegistryClient) AddDependencies(request *MircroServiceDependencyRequest
// AddSchemas adds a schema contents to the services registered in service-center
func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo string) error {
if microServiceID == "" {
return errors.New("invalid microserviceID")
return errors.New("invalid micro service ID")
}

schemaURL := c.formatURL(fmt.Sprintf("%s%s/%s%s/%s", MSAPIPath, MicroservicePath, microServiceID, SchemaPath, schemaName), nil, nil)
request := &MicroServiceInstanceSchemaUpdateRequest{
SchemaContent: schemaInfo,
h := sha256.New()
_, err := h.Write([]byte(schemaInfo))
if err != nil {
return err
}
request := &proto.ModifySchemaRequest{
SchemaId: schemaName,
ServiceId: microServiceID,
Schema: schemaInfo,
Summary: fmt.Sprintf("%x", h.Sum(nil)),
}
body, err := json.Marshal(request)
if err != nil {
Expand All @@ -339,7 +349,7 @@ func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo strin
}

if resp == nil {
return fmt.Errorf("Addschemas failed, response is empty")
return fmt.Errorf("add schemas failed, response is empty")
}

if resp.StatusCode != http.StatusOK {
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ module github.com/go-chassis/go-sc-client

require (
github.com/cenkalti/backoff v2.0.0+incompatible
github.com/go-chassis/go-chassis v1.1.0
github.com/go-chassis/go-chassis v1.1.3
github.com/go-chassis/paas-lager v0.0.0-20181123014243-005283cca84c
github.com/go-mesh/openlogging v0.0.0-20181122085847-3daf3ad8ed35
github.com/golang/protobuf v1.2.0
github.com/gorilla/websocket v1.4.0
github.com/stretchr/testify v1.2.2
golang.org/x/net v0.0.0-20180824152047-4bcd98cce591
google.golang.org/grpc v1.14.0

)
Loading

0 comments on commit af4152b

Please sign in to comment.