Documentation ¶
Overview ¶
Package ctxutil provides some helper functions which makes the context.Context object seemed to be an typed struct You don't need to know the keys just Set and Get
Attention: Before calling IncDBTime or IncRedisTime to accumulate the overall time you need call SetDBTime first.
Index ¶
- Variables
- func Format(ctx context.Context) (result string, finalErr error)
- func GetCaller(ctx context.Context) string
- func GetCookies(ctx context.Context) ([]*http.Cookie, error)
- func GetDBTime(ctx context.Context) (time.Duration, error)
- func GetDegrade(ctx context.Context) int
- func GetHTTPRequest(ctx context.Context) (*http.Request, error)
- func GetHintCode(ctx context.Context) (int64, error)
- func GetHintContent(ctx context.Context) (string, error)
- func GetLang(ctx context.Context) (string, error)
- func GetRedisTime(ctx context.Context) (time.Duration, error)
- func GetRequestInTs(ctx context.Context) (int64, error)
- func GetRequestTimeout(ctx context.Context) (int64, error)
- func GetSpanID(ctx context.Context) (string, error)
- func GetToken(ctx context.Context) (string, error)
- func GetTraceID(ctx context.Context) (string, error)
- func IncDBTime(ctx context.Context, delta time.Duration) (context.Context, error)
- func IncRedisTime(ctx context.Context, delta time.Duration) (context.Context, error)
- func SetCaller(ctx context.Context, caller string) context.Context
- func SetCookies(ctx context.Context, cks []*http.Cookie) context.Context
- func SetDBTime(ctx context.Context) context.Context
- func SetDegrade(ctx context.Context, sed int) context.Context
- func SetHTTPRequest(ctx context.Context, r *http.Request) context.Context
- func SetHintCode(ctx context.Context, hintCode int64) context.Context
- func SetHintContent(ctx context.Context, hintContent string) context.Context
- func SetLang(ctx context.Context, language string) context.Context
- func SetRedisTime(ctx context.Context) context.Context
- func SetRequestInTs(ctx context.Context, ts int64) context.Context
- func SetRequestTimeout(ctx context.Context, to int64) context.Context
- func SetSpanID(ctx context.Context, spanID string) context.Context
- func SetToken(ctx context.Context, token string) context.Context
- func SetTraceID(ctx context.Context, traceID string) context.Context
- func TraceString(ctx context.Context) string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotExist specifies that the data you want to retrive is missed ErrNotExist = errors.New("key is not existed in the context") // ErrDurationNotSetted reports that duration must be setted before you use it to do accumulation ErrDurationNotSetted = errors.New("duration must be setted at the beginning of the goroutine") //ErrWrongType ... ErrWrongType = errors.New("wrong type") )
Functions ¶
func GetHTTPRequest ¶
GetHTTPRequest ...
func GetHintCode ¶
GetHintCode gets hintCode from context, if hintCode not exists, ErrNotExist will be returned
func GetHintContent ¶
GetHintContent gets hintContent from context, if hintContent not exists, ErrNotExist will be returned
func GetLang ¶
GetLang gets language from context if langguage not exists, ErrNotExist will be returned
func GetRedisTime ¶
GetRedisTime returns the accumulated time for operating redis
func GetRequestInTs ¶
GetRequestInTs 获取请求的时间戳 毫秒位
func GetRequestTimeout ¶
GetRequestTimeout 上游超时要求 毫秒位
func GetSpanID ¶
GetSpanID gets spanID from context, if spanID not exists, ErrNotExist will be returned
func GetTraceID ¶
GetTraceID gets traceID from context, if traceID not exists, ErrNotExist will be returned
func IncDBTime ¶
IncDBTime accumulates the time for operating database you must call SetDBTime before use this function
func IncRedisTime ¶
IncRedisTime accumulates the time for operating redis you must call SetRedisTime before use this function
func SetHTTPRequest ¶
SetHTTPRequest ...
func SetHintCode ¶
SetHintCode sets the hintCode into context
func SetHintContent ¶
SetHintContent sets hintContent into context
func SetRedisTime ¶
SetRedisTime initialize the time counter for redis
func SetRequestInTs ¶
SetRequestInTs 请求的时间戳 毫秒位
func SetRequestTimeout ¶
SetRequestTimeout 上游超时要求 毫秒位
func SetTraceID ¶
SetTraceID sets traceID into context
func TraceString ¶
TraceString is the same as Format,but only return string that is, if there's an error occurs, TraceString will return "ctx_format=unset"
Types ¶
This section is empty.