xcontext

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// 统一前缀
	RASSE_PREFIX = "x-rasse-"
	// 业务链路跟踪Key
	BIZ_TRACE_KEY = RASSE_PREFIX + "biz-id"
	// 用户信息
	USER_KEY = RASSE_PREFIX + "user"
	// 用户信息
	USERNAME_KEY = RASSE_PREFIX + "user-name"
	// 用户信息
	USERID_KEY = RASSE_PREFIX + "user-id"
	// 请求唯一ID
	RASSE_TRACE_KEY = RASSE_PREFIX + "trace-id"
	// 全链路跟踪配置
	MESH_CONFIG_KEY = "mesh.headers"
	// 多语言
	LANG_KEY = RASSE_PREFIX + "lang"
)

Variables

View Source
var DEFAULT_LANG = "zh-CN"

参考规范:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language

View Source
var DEFAULT_MESH_TRACE_KEYS = []string{
	"x-request-id",
	"x-b3-traceid",
	"x-b3-spanid",
	"x-b3-parentspanid",
	"x-b3-sampled",
	"x-b3-flags",
	"x-ot-span-xcontext",
	"x-envoy-attempt-count",
	"x-envoy-external-address",
	"x-envoy-original-path"}

默认的Mesh 的APM KEY

Functions

func GetMeshKeys

func GetMeshKeys() []string

func ToMap

func ToMap(ctx XContext) map[string]string

Types

type BizTrace

type BizTrace string

type EmptyContext

type EmptyContext struct {
	RawContext context.Context
	Protocol   ProtocolType
	Trace      RasseTrace
	Mesh       MeshTrace
	User       UserInfo
	Biz        BizTrace
	Lang       LangInfo
}

EmptyContext

func NewEmptyContext

func NewEmptyContext() *EmptyContext

返回一个空的上下文

func (*EmptyContext) Deadline

func (ctx *EmptyContext) Deadline() (deadline time.Time, ok bool)

func (*EmptyContext) Done

func (ctx *EmptyContext) Done() <-chan struct{}

func (*EmptyContext) Err

func (ctx *EmptyContext) Err() error

func (*EmptyContext) Get

func (ctx *EmptyContext) Get(key string) (value interface{}, exist bool)

func (*EmptyContext) GetBizTrace

func (ctx *EmptyContext) GetBizTrace() BizTrace

func (*EmptyContext) GetLang

func (ctx *EmptyContext) GetLang() LangInfo

func (*EmptyContext) GetMeshTrace

func (ctx *EmptyContext) GetMeshTrace() MeshTrace

func (*EmptyContext) GetProtocol

func (ctx *EmptyContext) GetProtocol() ProtocolType

func (*EmptyContext) GetRasseTrace

func (ctx *EmptyContext) GetRasseTrace() RasseTrace

func (*EmptyContext) GetRawContext

func (ctx *EmptyContext) GetRawContext() interface{}

===== rasseContext start ======

func (*EmptyContext) GetUserInfo

func (ctx *EmptyContext) GetUserInfo() UserInfo

func (*EmptyContext) Set

func (ctx *EmptyContext) Set(key string, value interface{})

func (*EmptyContext) Value

func (ctx *EmptyContext) Value(key interface{}) interface{}

type LangInfo

type LangInfo struct {
	Code string `json:"code"`
}

type MeshTrace

type MeshTrace map[string]string

type ProtocolType

type ProtocolType int32

协议

const (
	Gin ProtocolType
	Trpc
	Test
	TDMQ
)

func (ProtocolType) String

func (p ProtocolType) String() string

type RasseTrace

type RasseTrace string

type UserInfo

type UserInfo struct {
	UserId   string `json:"user_id"`
	UserName string `json:"user_name"`
}

type XContext

type XContext interface {
	context.Context
	// 获取原生的context
	GetRawContext() interface{}
	// 获取当前协议
	GetProtocol() ProtocolType
	// 获取全链路跟踪信息
	GetMeshTrace() MeshTrace
	// 获取请求跟踪信息
	GetRasseTrace() RasseTrace
	//  获取用户信息
	GetUserInfo() UserInfo
	// 获取语言信息
	GetLang() LangInfo
	// 获取业务链路跟踪信息
	GetBizTrace() BizTrace
	//  从上下文中获取内容
	Get(key string) (value interface{}, exist bool)
	// 给上下文赋值
	Set(key string, value interface{})
}

rasse 上下文,与协议无关。

func NewTestContext

func NewTestContext() XContext

NewTestContext 构造测试XContext

Jump to

Keyboard shortcuts

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