Documentation ¶
Index ¶
- Constants
- func Derive(src, dest context.Context) context.Context
- func StreamClientInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, ...) (grpc.ClientStream, error)
- func StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func With(ctx context.Context, sc ServiceContext) context.Context
- type ServiceContext
- func (sc ServiceContext) AllVariables() map[string]string
- func (sc ServiceContext) Hash() string
- func (sc ServiceContext) InjectRequest(r *http.Request)
- func (sc ServiceContext) Services() []string
- func (sc ServiceContext) Specs() []string
- func (sc ServiceContext) Tag(serviceName string) string
- func (sc ServiceContext) Variable(key string) (string, bool)
Constants ¶
const (
// ServiceContextMetadataKey is key to used in GRPC Context.
ServiceContextMetadataKey = "consul-tag"
)
Variables ¶
This section is empty.
Functions ¶
func StreamClientInterceptor ¶
func StreamClientInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)
StreamClientInterceptor injects log context into outgoing grpc request.
func StreamServerInterceptor ¶
func StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
StreamServerInterceptor retrieve log context from incoming grpc request.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
UnaryClientInterceptor injects log context into outgoing grpc request.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
UnaryServerInterceptor retrieve log context from incoming grpc request.
Types ¶
type ServiceContext ¶
ServiceContext help choose the tag to call the right services. New(2021 May): this context also serves the service variables instead of just service tags. The underlying map combines two kinds of context:
Service Tag: the key with no speicified prefix Service Variables: the key with prefix "var/"
func FromContext ¶
func FromContext(ctx context.Context) ServiceContext
FromContext extracts service context from general context.
func FromRequest ¶
func FromRequest(r *http.Request) ServiceContext
FromRequest extracts the service context embeded in the http request.
func Merge ¶
func Merge(a, b ServiceContext) ServiceContext
Merge two ServiceContext together, and returns a new ServiceContext.
func New ¶
func New(specs []string) ServiceContext
New service tag spcification in format {ServiceName}:{Tag} into ServiceContext.
func NewWithVariables ¶
func NewWithVariables(services []string, vars map[string]string) ServiceContext
NewWithVariables service tags and variables into ServiceContext.
func (ServiceContext) AllVariables ¶
func (sc ServiceContext) AllVariables() map[string]string
func (ServiceContext) Hash ¶
func (sc ServiceContext) Hash() string
func (ServiceContext) InjectRequest ¶
func (sc ServiceContext) InjectRequest(r *http.Request)
InjectRequest embeds the service context into an http request, which will be recognized by CM MicroService framework.
func (ServiceContext) Services ¶
func (sc ServiceContext) Services() []string
Services returns only service names included in context.
func (ServiceContext) Specs ¶
func (sc ServiceContext) Specs() []string
Specs returns a wired format to pass as string slices.
func (ServiceContext) Tag ¶
func (sc ServiceContext) Tag(serviceName string) string
Tag returns the tag for a given service name.