tags

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultTagsPrefix = "fx-tags"
)

Variables

View Source
var (
	ErrMalformedTags  = errors.New("grpctags: Failed to marshal/unmarshal tags")
	ErrInvalidCarrier = errors.New("grpctags: Invalid Inject/Extract carrier")
	ErrInvalidTagsVal = errors.New("grpctags: Invalid tagsVal")
	ErrTagsValNull    = errors.New("grpctags: tagsVal is string null")
)
View Source
var (
	NoopTags = &noopTags{}
)

Functions

func UnaryClientInterceptor

func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a new unary server interceptor for OpenTracing.

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that sets the values for request tags.

func WithTags

func WithTags(ctx context.Context, tags Tags) context.Context

WithTags returns a new context that carries provided tags

Types

type Extractor

type Extractor interface {
	Extract(reader interface{}) (Tags, error)
}

type Injector

type Injector interface {
	Inject(tags Tags, carrier interface{}) error
}

type Option

type Option func(*options)

func WithTagsPrefix

func WithTagsPrefix(tagsPrefix string) Option

WithTagsPrefix set header tags name

type Tags

type Tags interface {
	// Set sets the given key in the metadata tags.
	Set(key string, value interface{}) Tags
	// Has checks if the given key exists.
	Has(key string) bool
	// Get returns value of given key
	Get(key string) interface{}
	// Values returns a map of key to values.
	// Do not modify the underlying map, please use Set instead.
	Values() map[string]interface{}

	// Foreach some kind like visitor pattern , each element pair will call f func
	//  and if accept return with error , the whole Foreach will return error
	// it some kind like each implementation in ruby https://ruby-doc.org/core-2.7.2/Hash.html#method-i-each
	//todo, require to review the necessary of Foreach to return error
	Foreach(f func(key string, val interface{}) error) error

	Len() int
}

Tags is the interface used for storing request tags between Context calls. The default implementation is *not* thread safe, and should be handled only in the context of the request.

func FromContext

func FromContext(ctx context.Context) Tags

FromContext returns a pre-existing Tags object in the Context. If the context wasn't set in a tag interceptor, a no-op Tag storage is returned that will *not* be propagated in context.

Jump to

Keyboard shortcuts

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