Documentation ¶
Index ¶
- Constants
- Variables
- func Bool(ctx context.Context, key string) bool
- func Equal(a, b Codes) bool
- func EqualError(code Codes, err error) bool
- func Int64(ctx context.Context, key string) int64
- func IsIncomingKey(key string) (ok bool)
- func IsOutgoingKey(key string) bool
- func NewContext(ctx context.Context, md Metadata) context.Context
- func Range(ctx context.Context, rangeFunc func(key string, value interface{}), ...)
- func Register(l string, cm map[int]string)
- func ToString(ctx context.Context, key string) string
- func Value(ctx context.Context, key string) interface{}
- func WithContext(c context.Context) context.Context
- type Code
- type Codes
- type Metadata
- type Status
Constants ¶
const ( // Network RemoteIP = "remote_ip" RemotePort = "remote_port" ServerAddr = "server_addr" ClientAddr = "client_addr" // Trace Trace = "trace" Caller = "caller" // Timeout Timeout = "timeout" // Dispatch Errors = "errors" Requests = "requests" // Mirror Mirror = "mirror" // Mid 外网账户用户id Mid = "mid" // NOTE: !!!业务可重新修改key名!!! // Device 客户端信息 Device = "device" // Criticality 重要性 Criticality = "criticality" )
metacode common key
Variables ¶
var ( OK = add(0) // 正确 Success = add(1) // 成功 NotModified = add(-304) // 木有改动 TemporaryRedirect = add(-307) // 撞车跳转 RequestErr = add(-400) // 请求错误 AccessDenied = add(-403) // 访问权限不足 NothingFound = add(-404) // 啥都木有 MethodNotAllowed = add(-405) // 不支持该方法 Conflict = add(-409) // 冲突 Canceled = add(-498) // 客户端取消请求 ServerErr = add(-500) // 服务器错误 Deadline = add(-504) // 服务调用超时 LimitExceed = add(-509) // 超出限制 ValidateErr = add(-512) // 服务器请求参数校验出错 )
All common code
Functions ¶
func IsIncomingKey ¶
IsIncomingKey represent this key should extract from rpc metadata.
func IsOutgoingKey ¶
IsOutgoingKey represent this key should propagate by rpc.
func NewContext ¶
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.
Types ¶
type Codes ¶
type Codes interface { // Error 有时错误返回字符串形式的代码 // 注意:请勿在监控器报告中使用“error”,即使它现在也可以使用 Error() string // Code 获取错误代码. Code() int // Message 获取错误信息. // param l string 语言 Message(l string) string // Details 获取错误详细信息,可能为nil. Details() []interface{} }
错误代码接口,其中包含代码和消息.
type Metadata ¶
type Metadata map[string]interface{}
Metadata is a mapping from metadata keys to values.
func FromContext ¶
FromContext returns the incoming metacode in ctx if it exists. The returned Metadata should not be modified. Writing to it may cause races. Modification should be made to copies of the returned Metadata.
func Join ¶
Join joins any number of mds into a single Metadata. The order of values for each key is determined by the order in which the mds containing those values are presented to Join.
func NewMetadata ¶
New creates an Metadata from a given key-value map.