contextKit

package
v3.0.911 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Set func(r *http.Request, key, val interface{}) = context.Set

	Get      func(r *http.Request, key interface{}) interface{}         = context.Get
	GetOk    func(r *http.Request, key interface{}) (interface{}, bool) = context.GetOk
	GetAll   func(r *http.Request) map[interface{}]interface{}          = context.GetAll
	GetAllOk func(r *http.Request) (map[interface{}]interface{}, bool)  = context.GetAllOk

	Delete func(r *http.Request, key interface{}) = context.Delete
	Clear  func(r *http.Request)                  = context.Clear

	Purge func(maxAge int) int = context.Purge

	// ClearHandler !!!: 能有效避免内存泄露.
	ClearHandler func(h http.Handler) http.Handler = context.ClearHandler
)

Functions

func WithKeyValue

func WithKeyValue[K comparable, V any](ctx context.Context, k K, v V) context.Context

WithKeyValue 在现有的上下文 (context) 中存储 1个 键值对,并返回一个新的上下文.

@param ctx 不能为nil

func WithKeyValueMap deprecated

func WithKeyValueMap[K comparable, V any](ctx context.Context, m map[K]V) context.Context

WithKeyValueMap 在现有的上下文 (context) 中存储 多个 键值对,并返回一个新的上下文.

Deprecated: 如果传参m的元素数量多,可能会导致嵌套太多层,这样不太好.

如果 键值对多 || 会频繁修改键值对,建议使用 gorilla/context(可能导致内存泄露!!!).

@param ctx 不能为nil

Types

This section is empty.

Jump to

Keyboard shortcuts

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