上下文类

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

包 gctx 对 context.Context 进行了封装,并提供了额外的上下文功能。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NeverDone

func NeverDone(ctx context.Context) context.Context

NeverDone 包装并返回一个新的上下文对象,该对象将永不完成, 这样可以禁止手动完成上下文,以使上下文能够传播到异步goroutine中。

func X创建

func X创建() context.Context

New 创建并返回一个包含上下文ID的上下文。

func X创建并从上下文

func X创建并从上下文(上下文 context.Context) context.Context

WithCtx 在给定的父级上下文 `ctx` 的基础上创建并返回一个包含上下文 ID 的新上下文。

func X取上下文id

func X取上下文id(上下文 context.Context) string

CtxId 从 context 中检索并返回上下文 id。

func X取初始化上下文

func X取初始化上下文() context.Context

GetInitCtx 返回初始化上下文。 初始化上下文用于在 `main` 或 `init` 函数中使用。

func X设置初始化上下文

func X设置初始化上下文(上下文 context.Context)

SetInitCtx 设置自定义初始化上下文。 注意:该函数不能在多个goroutine中被调用。

Types

type Ctx

type Ctx = context.Context // Ctx 是 context.Context 的简写别名。

type StrKey

type StrKey string // StrKey 是一种类型,用于将基本类型 string 包装为上下文键(Context key)。

Jump to

Keyboard shortcuts

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