diff --git a/protocol/grpc/client.go b/protocol/grpc/client.go index 0a98749aa999bbee99d092a47059e9b50a2c890c..af5ac3ff70f08c4c6f03020c8419a1df6aaf0524 100644 --- a/protocol/grpc/client.go +++ b/protocol/grpc/client.go @@ -77,7 +77,7 @@ func init() { } } -// Client ... +// Client return grpc connection and warp service stub type Client struct { *grpc.ClientConn invoker reflect.Value diff --git a/protocol/grpc/codec.go b/protocol/grpc/codec.go index 1f34674d641d1f02f455eda7800cbd56167b89f1..7235a3941baefcdce5964ae21dbdbfe9d6ca9cc8 100644 --- a/protocol/grpc/codec.go +++ b/protocol/grpc/codec.go @@ -29,10 +29,8 @@ import ( ) const ( - // json - CODEC_JSON = "json" - // proto - CODEC_PROTO = "proto" + codecJson = "json" + codecProto = "proto" ) func init() { @@ -44,18 +42,18 @@ func init() { }) } -// grpcJson ... type grpcJson struct { jsonpb.Marshaler jsonpb.Unmarshaler } -// implements grpc encoding package Codec interface method +// Name implements grpc encoding package Codec interface method, +// returns the name of the Codec implementation. func (_ grpcJson) Name() string { - return CODEC_JSON + return codecJson } -// implements grpc encoding package Codec interface method +// Marshal implements grpc encoding package Codec interface method,returns the wire format of v. func (j grpcJson) Marshal(v interface{}) (out []byte, err error) { if pm, ok := v.(proto.Message); ok { b := new(bytes.Buffer) @@ -68,7 +66,7 @@ func (j grpcJson) Marshal(v interface{}) (out []byte, err error) { return json.Marshal(v) } -// implements grpc encoding package Codec interface method +// Unmarshal implements grpc encoding package Codec interface method,Unmarshal parses the wire format into v. func (j grpcJson) Unmarshal(data []byte, v interface{}) (err error) { if pm, ok := v.(proto.Message); ok { b := bytes.NewBuffer(data) diff --git a/protocol/grpc/config.go b/protocol/grpc/config.go index 529b6068c9f708ff7af92ec58abd4cf6bb8c8b10..e8a9baac8999a009bab435a5bd4e70d102f77b56 100644 --- a/protocol/grpc/config.go +++ b/protocol/grpc/config.go @@ -22,44 +22,44 @@ import ( ) type ( - // ServerConfig + // ServerConfig currently is empty struct,for future expansion ServerConfig struct { } - // ClientConfig + // ClientConfig wrap client call parameters ClientConfig struct { // content type, more information refer by https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests ContentSubType string `default:"proto" yaml:"content_sub_type" json:"content_sub_type,omitempty"` } ) -// GetDefaultClientConfig ... +// GetDefaultClientConfig return grpc client default call options func GetDefaultClientConfig() ClientConfig { return ClientConfig{ - ContentSubType: CODEC_PROTO, + ContentSubType: codecProto, } } -// GetDefaultServerConfig ... +// GetDefaultServerConfig currently return empty struct,for future expansion func GetDefaultServerConfig() ServerConfig { return ServerConfig{} } -// GetClientConfig ... +// GetClientConfig return grpc client custom call options func GetClientConfig() ClientConfig { return ClientConfig{} } -// clientConfig Validate ... +// Validate check if custom config encoding is supported in dubbo grpc func (c *ClientConfig) Validate() error { - if c.ContentSubType != CODEC_JSON && c.ContentSubType != CODEC_PROTO { + if c.ContentSubType != codecJson && c.ContentSubType != codecProto { return perrors.Errorf(" dubbo-go grpc codec currently only support proto銆乯son, %s isn't supported,"+ " please check protocol content_sub_type config", c.ContentSubType) } return nil } -// severConfig Validate ... +// Validate currently return empty struct,for future expansion func (c *ServerConfig) Validate() error { return nil }