context

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderGinContextKey = "gin-context"
	HttpRequestKey      = "Http-Request"
)

http 的header

View Source
const CommonContextKey = "context"

Variables

View Source
var Canceled = context.Canceled
View Source
var DeadlineExceeded = context.DeadlineExceeded

Functions

func WithCancel

func WithCancel(parent context.Context) (IContext, CancelFunc)

func WithContext

func WithContext(ctx context.Context) *contextImpl

func WithTimeout

func WithTimeout(goctx context.Context, d time.Duration) (IContext, CancelFunc)

Types

type CancelFunc

type CancelFunc = context.CancelFunc

type Context

type Context = IContext

type IContext

type IContext interface {
	context.Context
	Set(key string, value interface{})
	// SetMeta与Set的区别是 SetMeta设置的key在ctx.GetHeaderMap()时会返回
	// 而这个map通常是ddns client请求别的服务时需要透传过去的Header
	// 故如果你觉得这个key需要进行透传,请用SetMeta
	SetMeta(key string, value string)
	WithValue(key interface{}, val interface{}) IContext
	WithCancel() (IContext, CancelFunc)
	WithTimeout(d time.Duration) (IContext, CancelFunc)

	GetHeaders() http.Header

	Get(key string) (value interface{}, exists bool)

	GetString(key string) (v string)
	GetInt64(key string) (i int64)
	GetInt(key string) (i int)

	GetGoContext() context.Context
	GetAllKey() map[string]interface{}
	GetHttpRequest() *http.Request
	LogInfo(msg string, fields ...log.Field)
	LogError(msg string, fields ...log.Field)
}

func Background

func Background() IContext

func Ginform

func Ginform(c IGetter) IContext

func NewContext

func NewContext() IContext

func NewContextWithGinHeader

func NewContextWithGinHeader(c *gin.Context) IContext

func TODO

func TODO() IContext

func WithValue

func WithValue(parent context.Context, key interface{}, val interface{}) IContext

type IGetter

type IGetter interface {
	//为了去除去gin.Context的直接依赖
	Get(string) (value interface{}, exists bool)
}

Jump to

Keyboard shortcuts

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