metadata

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RemoteIP   = "remote_ip"
	RemotePort = "remote_port"
	ServerAddr = "server_addr"
	ClientAddr = "client_addr"

	Color = "color"

	Trace  = "trace"
	Caller = "caller"

	// Log
	Notice = "notice"

	Timeout = "timeout"

	CPUUsage = "cpu_usage"
	Errors   = "errors"
	Requests = "requests"

	Mirror = "mirror"

	Mid = "mid"

	Uid = "uid"

	Username = "username"

	// Device
	Device = "device"

	// Cluster cluster info key
	Cluster = "cluster"
)

metadata common key

Variables

This section is empty.

Functions

func Bool

func Bool(ctx context.Context, key string) bool

Bool get boolean from metadata in context use strconv.Parse.

func CtxFromGinContext

func CtxFromGinContext(c *gin.Context) (context.Context, bool)

func GinCtxWithCtx

func GinCtxWithCtx(c *gin.Context, ctx context.Context)

func Int64

func Int64(ctx context.Context, key string) int64

Int64 get int64 value from metadata in context

func NewContext

func NewContext(ctx context.Context, md MD) context.Context

NewContext creates a new context with md attached.

func NewContext4Gin

func NewContext4Gin() context.Context

func String

func String(ctx context.Context, key string) string

String get string value from metadata in context

func Value

func Value(ctx context.Context, key string) interface{}

Value get value from metadata in context return nil if not found

func WithContext

func WithContext(c context.Context) context.Context

WithContext return no deadline context and retain metadata.

Types

type MD

type MD map[string]interface{}

MD is a mapping from metadata keys to values.

func FromContext

func FromContext(ctx context.Context) (md MD, ok bool)

FromContext returns the incoming metadata in ctx if it exists. The returned MD should not be modified. Writing to it may cause races. Modification should be made to copies of the returned MD.

func Join

func Join(mds ...MD) 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 mds containing those values are presented to Join.

func New

func New(m map[string]interface{}) MD

New creates an MD from a given key-value map.

func Pairs

func Pairs(kv ...interface{}) MD

Pairs returns an MD formed by the mapping of key, value ... Pairs panics if len(kv) is odd.

func (MD) Copy

func (md MD) Copy() MD

Copy returns a copy of md.

func (MD) Len

func (md MD) Len() int

Len returns the number of items in md.

Jump to

Keyboard shortcuts

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