biz

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ContextKeyAppId         = "hd-app-id"   // 应用ID
	ContextKeyClient        = "hd-client"   // 客户端
	ContextKeyRelease       = "hd-release"  // 版本号
	ContextKeyTsn           = "hd-tsn"      // tenant sn
	ContextKeyTid           = "hd-tid"      // tenant id
	ContextKeyUid           = "hd-uid"      // user id
	ContextKeyUsn           = "hd-usn"      // user sn
	ContextKeyRoleIds       = "hd-role-ids" // role ids
	ContextKeyCaller        = "dapr-caller-app-id"
	ContextKeyDbTransaction = "hd-db-tx"
)
View Source
const (
	ErrCodeInternal // internal error
)

define utils error code

View Source
const (
	ErrCodeModuleRoot = ErrCodeStart * (1 + iota)
)

ErrCodeModuleRoot define error code module, e,g: 10000, 20000, 30000...

View Source
const ErrCodeStart = 10000

ErrCodeStart 业务逻辑错误代码开始值

Variables

This section is empty.

Functions

func NewOutgoingGrpcContext

func NewOutgoingGrpcContext(ctx Context) context.Context

func ToGrpcError

func ToGrpcError(err error) error

Types

type Context

type Context interface {
	WithValue(kvs ...any) Context // 添加键值
	WithTid(tid int64) Context    // 快捷函数设置tid
	WithTx(tx any) Context        // 快捷函数设置tx
	Value(key any) (any, bool)    // 获取键值
	MD() map[string][]string      // 转换成GRPC metadata类型
	Tid() int64                   // 获取租户ID
	Uid() int64                   // 获取用户ID
	Usn() string                  // 获取用户SN
	AppId() string                // 获取应用ID
	RoleIds() []int64             // 获取角色ID列表
}

func NewContext

func NewContext(kvs ...any) Context

func NewFromIncomingGrpcContext

func NewFromIncomingGrpcContext(ctx context.Context) Context

type Error

type Error interface {
	error
	Code() int
}

func FromGrpcError

func FromGrpcError(err error) Error

FromGrpcError 从grpc status error获取额外的错误信息

func InternalError

func InternalError(message string) Error

func NewError

func NewError[T constraints.Integer](code T, message string) Error

NewError new error with error code

Jump to

Keyboard shortcuts

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