bizctx

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaKeyAppKey  = "hd-app-id"   // 应用ID
	MetaKeySource  = "hd-source"   // 请求来源, 例如:第三方API回调
	MetaKeyAppCode = "hd-app-code" // 应用类型Code
	MetaKeyTid     = "hd-tid"      // tenant id
	MetaKeyUid     = "hd-uid"      // user id
	MetaKeyUsn     = "hd-usn"      // user sn
	MetaKeyRoleIds = "hd-role-ids" // role ids
)

Variables

This section is empty.

Functions

func GetAppCode

func GetAppCode(ctx context.Context) string

func GetAppId

func GetAppId(ctx context.Context) string

func GetRoleIds

func GetRoleIds(ctx context.Context) []int64

func GetSource

func GetSource(ctx context.Context) string

func GetTid

func GetTid(ctx context.Context) int64

func GetUid

func GetUid(ctx context.Context) int64

func New

func New(kvs ...any) context.Context

New 创建一个kvs的 context.Context,包含空的 metadata 和 Transactor

func NewFromIncomingGrpcContext

func NewFromIncomingGrpcContext(ctx context.Context) context.Context

NewFromIncomingGrpcContext 从 gRPC context 中提取 metadata 并存储到 context.Context

func NewOutgoingGrpcContext

func NewOutgoingGrpcContext(ctx context.Context) context.Context

NewOutgoingGrpcContext 将 context 中的 metadata 转换为 gRPC outgoing context

func WithMetaData

func WithMetaData(ctx context.Context, md MetaData) context.Context

WithMetaData 将 metadata 存入 context

func WithRoleIds

func WithRoleIds(ctx context.Context, roleIds []int64) context.Context

WithRoleIds 将角色 ID 列表存入 context

func WithTid

func WithTid(ctx context.Context, tid int64) context.Context

WithTid 将租户 ID 存入 context

func WithUid

func WithUid(ctx context.Context, uid int64) context.Context

WithUid 将用户 ID 存入 context

Types

type MetaData

type MetaData interface {
	Set(key string, val any)
	Get(key string) (any, bool)
	AsGRPCMetaData() map[string][]string
	GetInt64(key string) int64
	GetString(key string) string
	GetInt64Slice(key string) []int64
}

func GetMetaData

func GetMetaData(ctx context.Context) MetaData

GetMetaData 从 context 中获取 MetaData

type Transactor

type Transactor interface {
	Ref(tx any)      // 引用, 因为可能嵌套NewTransactor, 这里加入计数
	Unref()          // 解引用, 如果计数为0,表示需要Finalize,并Destroy tx
	GetTx() any      // 获取Tx
	ReachRoot() bool // 是否到达最外层
}

func GetTransactor

func GetTransactor(ctx context.Context) Transactor

GetTransactor 从 context 中获取 Transactor

Jump to

Keyboard shortcuts

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