servicecontext

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceContextMetadataKey is key to used in GRPC Context.
	ServiceContextMetadataKey = "consul-tag"
)

Variables

This section is empty.

Functions

func Derive

func Derive(src, dest context.Context) context.Context

Derive extracts service context from src context, to merge it into dest context.

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.

func With

With embeds service context into general context

Types

type ServiceContext

type ServiceContext map[string]string

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.

func (ServiceContext) Variable

func (sc ServiceContext) Variable(key string) (string, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL