contextKit

package
v3.1.101 Latest Latest
Warning

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

Go to latest
Published: Nov 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 AttachKeyValue

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

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

PS: (1) 同一个Context实例,多次调用此方法 且 key相同,则覆盖之前的值. (2) 对于同一个Context实例,不推荐调用太多次此方法,因为: 每调用一次就是嵌套一层,会嵌套太多层.

@param ctx 不能为nil

func AttachKeyValueMap deprecated

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

AttachKeyValueMap 在现有的上下文 (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