Skip to content
Snippets Groups Projects
Commit 96c699aa authored by xuxiaoliang's avatar xuxiaoliang
Browse files

add public method 、struc comment

parent 65e2b21e
No related branches found
No related tags found
No related merge requests found
......@@ -77,7 +77,7 @@ func init() {
}
}
// Client ...
// Client return grpc connection and warp service stub
type Client struct {
*grpc.ClientConn
invoker reflect.Value
......
......@@ -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)
......
......@@ -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% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment