contextx

package
v0.11.33 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-09 15:55:51 * @FilePath: \go-toolbox\pkg\contextx\context.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsContext added in v0.11.29

func IsContext(ctx context.Context) bool

IsContext 检查上下文是否是 Context

Types

type Context added in v0.11.29

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

Context 是一个自定义的上下文,支持多个值的存储

func MergeContext added in v0.11.29

func MergeContext(ctxs ...context.Context) *Context

MergeContext 合并多个上下文为一个 Context

func NewContext added in v0.11.29

func NewContext(parent context.Context, pool *syncx.LimitedPool) *Context

NewContext 创建一个新的 Context,允许用户传入自定义的字节切片池

func NewContextWithCancel added in v0.11.29

func NewContextWithCancel(parent context.Context, pool *syncx.LimitedPool) *Context

NewContextWithCancel 创建一个可以手动取消的 Context

func NewContextWithTimeout added in v0.11.29

func NewContextWithTimeout(parent context.Context, timeout time.Duration, pool *syncx.LimitedPool) *Context

NewContextWithTimeout 创建一个带有超时的 Context

func NewContextWithValue

func NewContextWithValue(parent context.Context, key, val interface{}, pool *syncx.LimitedPool) (*Context, error)

NewContextWithValue 在父上下文中设置值并返回新的 Context

func NewLocalContextWithValue

func NewLocalContextWithValue(ctx *Context, key, val interface{}) (*Context, error)

NewLocalContextWithValue 在当前 Context 中设置局部值

func (*Context) Cancel added in v0.11.29

func (c *Context) Cancel()

Cancel 取消上下文

func (*Context) Deadline added in v0.11.29

func (c *Context) Deadline() (deadline time.Time, ok bool)

Deadline 返回上下文的截止时间

func (*Context) Remove added in v0.11.29

func (c *Context) Remove(key interface{})

Remove 删除指定键的键值对

func (*Context) Set added in v0.11.29

func (c *Context) Set(key, value interface{}) error

Set 设置指定键的值并返回错误

func (*Context) String added in v0.11.29

func (c *Context) String() string

String 返回上下文的字符串表示

func (*Context) Value added in v0.11.29

func (c *Context) Value(key interface{}) interface{}

Value 获取指定键的值

func (*Context) Values added in v0.11.29

func (c *Context) Values() map[interface{}]interface{}

Values 返回当前上下文中所有的键值对

Jump to

Keyboard shortcuts

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