Address the comments
This commit is contained in:
@ -97,7 +97,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddrMetadataGRPCLB contains the information the name resolver for grpclb should provide. The
|
// AddrMetadataGRPCLB contains the information the name resolver for grpclb should provide. The
|
||||||
// name resolver used by grpclb balancer is required to provide this type of metadata in
|
// name resolver used by the grpclb balancer is required to provide this type of metadata in
|
||||||
// its address updates.
|
// its address updates.
|
||||||
type AddrMetadataGRPCLB struct {
|
type AddrMetadataGRPCLB struct {
|
||||||
// AddrType is the type of server (grpc load balancer or backend).
|
// AddrType is the type of server (grpc load balancer or backend).
|
||||||
|
@ -51,7 +51,7 @@ func DecodeKeyValue(k, v string) (string, string, error) {
|
|||||||
// two convenience functions New and Pairs to generate MD.
|
// two convenience functions New and Pairs to generate MD.
|
||||||
type MD map[string][]string
|
type MD map[string][]string
|
||||||
|
|
||||||
// New creates a MD from given key-value map.
|
// New creates an MD from a given key-value map.
|
||||||
// Keys are automatically converted to lowercase.
|
// Keys are automatically converted to lowercase.
|
||||||
func New(m map[string]string) MD {
|
func New(m map[string]string) MD {
|
||||||
md := MD{}
|
md := MD{}
|
||||||
@ -81,19 +81,19 @@ func Pairs(kv ...string) MD {
|
|||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
|
|
||||||
// Len returns the number of items in MD.
|
// Len returns the number of items in md.
|
||||||
func (md MD) Len() int {
|
func (md MD) Len() int {
|
||||||
return len(md)
|
return len(md)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy returns a copy of MD.
|
// Copy returns a copy of md.
|
||||||
func (md MD) Copy() MD {
|
func (md MD) Copy() MD {
|
||||||
return Join(md)
|
return Join(md)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join joins any number of MDs into a single MD.
|
// Join joins any number of mds into a single MD.
|
||||||
// The order of values for each key is determined by the order in which
|
// The order of values for each key is determined by the order in which
|
||||||
// the MDs containing those values are presented to Join.
|
// the mds containing those values are presented to Join.
|
||||||
func Join(mds ...MD) MD {
|
func Join(mds ...MD) MD {
|
||||||
out := MD{}
|
out := MD{}
|
||||||
for _, md := range mds {
|
for _, md := range mds {
|
||||||
@ -112,12 +112,12 @@ func NewContext(ctx context.Context, md MD) context.Context {
|
|||||||
return NewOutgoingContext(ctx, md)
|
return NewOutgoingContext(ctx, md)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIncomingContext creates a new context with incoming MD attached.
|
// NewIncomingContext creates a new context with incoming md attached.
|
||||||
func NewIncomingContext(ctx context.Context, md MD) context.Context {
|
func NewIncomingContext(ctx context.Context, md MD) context.Context {
|
||||||
return context.WithValue(ctx, mdIncomingKey{}, md)
|
return context.WithValue(ctx, mdIncomingKey{}, md)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOutgoingContext creates a new context with outgoing MD attached.
|
// NewOutgoingContext creates a new context with outgoing md attached.
|
||||||
func NewOutgoingContext(ctx context.Context, md MD) context.Context {
|
func NewOutgoingContext(ctx context.Context, md MD) context.Context {
|
||||||
return context.WithValue(ctx, mdOutgoingKey{}, md)
|
return context.WithValue(ctx, mdOutgoingKey{}, md)
|
||||||
}
|
}
|
||||||
@ -127,17 +127,17 @@ func FromContext(ctx context.Context) (md MD, ok bool) {
|
|||||||
return FromIncomingContext(ctx)
|
return FromIncomingContext(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromIncomingContext returns the incoming MD in ctx if it exists. The
|
// FromIncomingContext returns the incoming metadata in ctx if it exists. The
|
||||||
// returned md should be immutable. Writing to it may cause races.
|
// returned MD should not be modified. Writing to it may cause races.
|
||||||
// Modification should be made to copies of the returned md.
|
// Modification should be made to copies of the returned MD.
|
||||||
func FromIncomingContext(ctx context.Context) (md MD, ok bool) {
|
func FromIncomingContext(ctx context.Context) (md MD, ok bool) {
|
||||||
md, ok = ctx.Value(mdIncomingKey{}).(MD)
|
md, ok = ctx.Value(mdIncomingKey{}).(MD)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromOutgoingContext returns the outgoing MD in ctx if it exists. The
|
// FromOutgoingContext returns the outgoing metadata in ctx if it exists. The
|
||||||
// returned md should be immutable. Writing to it may cause races.
|
// returned MD should not be modified. Writing to it may cause races.
|
||||||
// Modification should be made to the copies of the returned md.
|
// Modification should be made to the copies of the returned MD.
|
||||||
func FromOutgoingContext(ctx context.Context) (md MD, ok bool) {
|
func FromOutgoingContext(ctx context.Context) (md MD, ok bool) {
|
||||||
md, ok = ctx.Value(mdOutgoingKey{}).(MD)
|
md, ok = ctx.Value(mdOutgoingKey{}).(MD)
|
||||||
return
|
return
|
||||||
|
@ -173,7 +173,8 @@ func Peer(peer *peer.Peer) CallOption {
|
|||||||
// immediately. Otherwise, the RPC client will block the call until a
|
// immediately. Otherwise, the RPC client will block the call until a
|
||||||
// connection is available (or the call is canceled or times out) and will retry
|
// connection is available (or the call is canceled or times out) and will retry
|
||||||
// the call if it fails due to a transient error. Please refer to
|
// the call if it fails due to a transient error. Please refer to
|
||||||
// https://github.com/grpc/grpc/blob/master/doc/fail_fast.md. Note: failFast is default to true.
|
// https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md.
|
||||||
|
// Note: failFast is default to true.
|
||||||
func FailFast(failFast bool) CallOption {
|
func FailFast(failFast bool) CallOption {
|
||||||
return beforeCall(func(c *callInfo) error {
|
return beforeCall(func(c *callInfo) error {
|
||||||
c.failFast = failFast
|
c.failFast = failFast
|
||||||
|
@ -125,8 +125,7 @@ type options struct {
|
|||||||
|
|
||||||
var defaultMaxMsgSize = 1024 * 1024 * 4 // use 4MB as the default message size limit
|
var defaultMaxMsgSize = 1024 * 1024 * 4 // use 4MB as the default message size limit
|
||||||
|
|
||||||
// A ServerOption sets options such as credentials, codec and keepalive
|
// A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
|
||||||
// parameters, etc.
|
|
||||||
type ServerOption func(*options)
|
type ServerOption func(*options)
|
||||||
|
|
||||||
// KeepaliveParams returns a ServerOption that sets keepalive and max-age parameters for the server.
|
// KeepaliveParams returns a ServerOption that sets keepalive and max-age parameters for the server.
|
||||||
|
Reference in New Issue
Block a user