metadata

package
v0.0.0-...-3ecd8c4 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: MIT Imports: 4 Imported by: 0

README

net/metadata

项目简介

用于储存各种元信息

Documentation

Index

Constants

View Source
const (

	// Network
	RemoteIP   = "remote_ip"
	RemotePort = "remote_port"
	ServerAddr = "server_addr"
	ClientAddr = "client_addr"

	// Router
	Cluster = "cluster"
	Color   = "color"

	// Trace
	Trace  = "trace"
	Caller = "caller"

	// Timeout
	Timeout = "timeout"

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

	// Mirror
	Mirror = "mirror"

	// Mid 外网账户用户id
	Mid = "mid" // NOTE: !!!业务可重新修改key名!!!

	// Device 客户端信息
	Device = "device"

	// Criticality 重要性
	Criticality = "criticality"
)

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 Int64

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

Int64 get int64 value from metadata in context

func IsIncomingKey

func IsIncomingKey(key string) (ok bool)

IsIncomingKey represent this key should extract from rpc metadata.

func IsOutgoingKey

func IsOutgoingKey(key string) bool

IsOutgoingKey represent this key should propagate by rpc.

func NewContext

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

NewContext creates a new context with md attached.

func Range

func Range(ctx context.Context, rangeFunc func(key string, value interface{}), filterFunc ...func(key string) bool)

Range range value from metadata in context filtered by filterFunc.

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