kratos: github.com/bilibili/kratos/pkg/net/metadata Index | Files

package metadata

import "github.com/bilibili/kratos/pkg/net/metadata"

Index

Package Files

key.go metadata.go

Constants

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

func Bool Uses

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

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

func Int64 Uses

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

Int64 get int64 value from metadata in context

func IsIncomingKey Uses

func IsIncomingKey(key string) (ok bool)

IsIncomingKey represent this key should extract from rpc metadata.

func IsOutgoingKey Uses

func IsOutgoingKey(key string) bool

IsOutgoingKey represent this key should propagate by rpc.

func NewContext Uses

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

NewContext creates a new context with md attached.

func Range Uses

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 Uses

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

String get string value from metadata in context

func Value Uses

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

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

func WithContext Uses

func WithContext(c context.Context) context.Context

WithContext return no deadline context and retain metadata.

type MD Uses

type MD map[string]interface{}

MD is a mapping from metadata keys to values.

func FromContext Uses

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 Uses

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 Uses

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

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

func Pairs Uses

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 Uses

func (md MD) Copy() MD

Copy returns a copy of md.

func (MD) Len Uses

func (md MD) Len() int

Len returns the number of items in md.

Package metadata imports 4 packages (graph) and is imported by 4 packages. Updated 2019-07-20. Refresh now. Tools for package owners.