context

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 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 any)
	// SetMeta与Set的区别是 SetMeta设置的key在ctx.GetHeaderMap()时会返回
	// 而这个map通常是ddns client请求别的服务时需要透传过去的Header
	// 故如果你觉得这个key需要进行透传,请用SetMeta
	SetMeta(key string, value string)
	WithValue(key any, val any) IContext
	WithCancel() (IContext, CancelFunc)
	WithTimeout(d time.Duration) (IContext, CancelFunc)

	GetHeaders() http.Header

	Get(key string) (value any, exists bool)

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

	GetGoContext() context.Context
	GetAllKey() map[string]any
	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 any) IContext

Ginform 将 *gin.Context 或 IContext 统一转换为 IContext 参数类型为 any:gin v1.10+ 的 Context.Get 签名变为 Get(any),无法再用小接口约束

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 any, val any) IContext

Jump to

Keyboard shortcuts

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