Documentation
¶
Index ¶
- Constants
- func GetAppCode(ctx context.Context) string
- func GetAppId(ctx context.Context) string
- func GetRoleIds(ctx context.Context) []int64
- func GetSource(ctx context.Context) string
- func GetTid(ctx context.Context) int64
- func GetUid(ctx context.Context) int64
- func New(kvs ...any) context.Context
- func NewFromIncomingGrpcContext(ctx context.Context) context.Context
- func NewOutgoingGrpcContext(ctx context.Context) context.Context
- func WithMetaData(ctx context.Context, md MetaData) context.Context
- func WithRoleIds(ctx context.Context, roleIds []int64) context.Context
- func WithTid(ctx context.Context, tid int64) context.Context
- func WithUid(ctx context.Context, uid int64) context.Context
- type MetaData
- type Transactor
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 GetRoleIds ¶
func NewFromIncomingGrpcContext ¶
NewFromIncomingGrpcContext 从 gRPC context 中提取 metadata 并存储到 context.Context
func NewOutgoingGrpcContext ¶
NewOutgoingGrpcContext 将 context 中的 metadata 转换为 gRPC outgoing context
func WithMetaData ¶
WithMetaData 将 metadata 存入 context
func WithRoleIds ¶
WithRoleIds 将角色 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 ¶
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
Click to show internal directories.
Click to hide internal directories.