Skip to content

Commit

Permalink
add public method 、struc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaoliang authored and xuxiaoliang committed Jun 9, 2020
1 parent 9dc28f0 commit e00853c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion protocol/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func init() {
}
}

// Client ...
// Client return grpc connection and warp service stub
type Client struct {
*grpc.ClientConn
invoker reflect.Value
Expand Down
16 changes: 7 additions & 9 deletions protocol/grpc/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ import (
)

const (
// json
CODEC_JSON = "json"
// proto
CODEC_PROTO = "proto"
codecJson = "json"
codecProto = "proto"
)

func init() {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions protocol/grpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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、json, %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
}

0 comments on commit e00853c

Please sign in to comment.