Documentation ¶
Index ¶
- func BoolToString(value bool) string
- func ByteToString(value byte) string
- func BytesToString(b []byte) string
- func ConditionalRetryByExponentialBackoff(f func() error, cond func() bool, maxRetries int, ...) error
- func Convert[A, B any](src A) B
- func Float32ToString(value float32) string
- func Float64ToString(value float64) string
- func GetError(err error) (int, error)
- func GoFormat(filePath string)
- func Handle(f func())
- func HandleErr(f func() error) error
- func HandleV[V any](v V, f func(v V))
- func Hostname() string
- func If[T any](expression bool, t T, f T) T
- func Int16ToString(value int16) string
- func Int32ToString(value int32) string
- func Int64ToString(value int64) string
- func Int8ToString(value int8) string
- func IntToString(value int) string
- func IsNumber(v any) bool
- func LaunchTime() time.Time
- func MarshalIndentJSON(v interface{}, prefix, indent string) []byte
- func MarshalJSON(v interface{}) []byte
- func MarshalJSONE(v interface{}) ([]byte, error)
- func MarshalToTargetWithJSON(src, dest interface{}) error
- func RegError(code int, message string) error
- func RegErrorRef(code int, message string, ref error) error
- func Retry(count int, interval time.Duration, f func() error) error
- func RetryAsync(count int, interval time.Duration, f func() error, callback func(err error))
- func RetryByExponentialBackoff(f func() error, maxRetries int, baseDelay, maxDelay time.Duration, ...) error
- func RetryByRule(f func() error, rule func(count int) time.Duration) error
- func RetryForever(interval time.Duration, f func() error)
- func RuneToString(value rune) string
- func SliceToString(value []string) string
- func StringToBool(value string) bool
- func StringToByte(value string) byte
- func StringToBytes(s string) []byte
- func StringToFloat32(value string) float32
- func StringToFloat64(value string) float64
- func StringToInt(value string) int
- func StringToInt16(value string) int16
- func StringToInt32(value string) int32
- func StringToInt64(value string) int64
- func StringToInt8(value string) int8
- func StringToRune(value string) rune
- func StringToSlice(value string) []string
- func StringToUint(value string) uint
- func StringToUint16(value string) uint16
- func StringToUint32(value string) uint32
- func StringToUint64(value string) uint64
- func StringToUint8(value string) uint8
- func Uint16ToString(value uint16) string
- func Uint32ToString(value uint32) string
- func Uint64ToString(value uint64) string
- func Uint8ToString(value uint8) string
- func UintToString(value uint) string
- func UnmarshalJSON(data []byte, v interface{}) error
- type LossCounter
- type Matcher
- type Permission
- func (slf *Permission[Code, EntityID]) AddPermission(entityId EntityID, permission ...Code)
- func (slf *Permission[Code, EntityID]) HasPermission(entityId EntityID, permission Code) bool
- func (slf *Permission[Code, EntityID]) RemovePermission(entityId EntityID, permission ...Code)
- func (slf *Permission[Code, EntityID]) SetPermission(entityId EntityID, permission ...Code)
- type StackGo
- type VerifyHandle
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToString ¶ added in v0.0.20
BytesToString 以零拷贝的方式将字节切片转换为字符串
func ConditionalRetryByExponentialBackoff ¶ added in v0.3.1
func ConditionalRetryByExponentialBackoff(f func() error, cond func() bool, maxRetries int, baseDelay, maxDelay time.Duration, multiplier, randomization float64) error
ConditionalRetryByExponentialBackoff 该函数与 RetryByExponentialBackoff 类似,但是可以被中断
- cond 为中断条件,当 cond 返回 false 时,将会中断重试
该函数通常用于在重试过程中,需要中断重试的场景,例如:
- 用户请求开始游戏,由于网络等情况,进入重试状态。此时用户再次发送开始游戏请求,此时需要中断之前的重试,避免重复进入游戏
func Convert ¶ added in v0.0.22
func Convert[A, B any](src A) B
Convert 以零拷贝的方式将一个对象转换为另一个对象
- 两个对象字段必须完全一致
- 该函数可以绕过私有字段的访问限制
func Float32ToString ¶ added in v0.0.31
Float32ToString float32 转换为字符串
func Float64ToString ¶ added in v0.0.31
Float64ToString float64 转换为字符串
func HandleV ¶ added in v0.0.8
func HandleV[V any](v V, f func(v V))
HandleV 执行 f 函数,如果 f 为 nil,则不执行
func Int16ToString ¶ added in v0.0.31
Int16ToString int16 转换为字符串
func Int32ToString ¶ added in v0.0.31
Int32ToString int32 转换为字符串
func Int64ToString ¶ added in v0.0.31
Int64ToString int64 转换为字符串
func MarshalIndentJSON ¶ added in v0.0.21
MarshalIndentJSON 将对象转换为 json
func MarshalJSON ¶ added in v0.0.21
func MarshalJSON(v interface{}) []byte
MarshalJSON 将对象转换为 json
- 当转换失败时,将返回 json 格式的空对象
func MarshalToTargetWithJSON ¶ added in v0.2.3
func MarshalToTargetWithJSON(src, dest interface{}) error
MarshalToTargetWithJSON 将对象转换为目标对象
func Retry ¶ added in v0.0.8
Retry 根据提供的 count 次数尝试执行 f 函数,如果 f 函数返回错误,则在 interval 后重试,直到成功或者达到 count 次数
func RetryAsync ¶ added in v0.0.8
RetryAsync 与 Retry 类似,但是是异步执行
- 传入的 callback 函数会在执行完毕后被调用,如果执行成功,则 err 为 nil,否则为错误信息
- 如果 callback 为 nil,则不会在执行完毕后被调用
func RetryByExponentialBackoff ¶ added in v0.2.9
func RetryByExponentialBackoff(f func() error, maxRetries int, baseDelay, maxDelay time.Duration, multiplier, randomization float64) error
RetryByExponentialBackoff 根据指数退避算法尝试执行 f 函数
- maxRetries:最大重试次数
- baseDelay:基础延迟
- maxDelay:最大延迟
- multiplier:延迟时间的乘数,通常为 2
- randomization:延迟时间的随机化因子,通常为 0.5
func RetryByRule ¶ added in v0.2.9
RetryByRule 根据提供的规则尝试执行 f 函数,如果 f 函数返回错误,则根据 rule 的返回值进行重试
- rule 将包含一个入参,表示第几次重试,返回值表示下一次重试的时间间隔,当返回值为 0 时,表示不再重试
- rule 的 count 将在 f 首次失败后变为 1,因此 rule 的入参将从 1 开始
func RetryForever ¶ added in v0.2.2
RetryForever 根据提供的 interval 时间间隔尝试执行 f 函数,如果 f 函数返回错误,则在 interval 后重试,直到成功
func SliceToString ¶ added in v0.0.31
SliceToString 切片转换为字符串
func StringToBytes ¶ added in v0.0.20
StringToBytes 以零拷贝的方式将字符串转换为字节切片
func StringToFloat32 ¶ added in v0.0.31
StringToFloat32 字符串转换为 float32
func StringToFloat64 ¶ added in v0.0.31
StringToFloat64 字符串转换为 float64
func StringToInt16 ¶ added in v0.0.31
StringToInt16 字符串转换为 int16
func StringToInt32 ¶ added in v0.0.31
StringToInt32 字符串转换为 int32
func StringToInt64 ¶ added in v0.0.31
StringToInt64 字符串转换为 int64
func StringToSlice ¶ added in v0.0.31
StringToSlice 字符串转换为切片
func StringToUint16 ¶ added in v0.0.31
StringToUint16 字符串转换为 uint16
func StringToUint32 ¶ added in v0.0.31
StringToUint32 字符串转换为 uint32
func StringToUint64 ¶ added in v0.0.31
StringToUint64 字符串转换为 uint64
func StringToUint8 ¶ added in v0.0.31
StringToUint8 字符串转换为 uint8
func Uint16ToString ¶ added in v0.0.31
Uint16ToString uint16 转换为字符串
func Uint32ToString ¶ added in v0.0.31
Uint32ToString uint32 转换为字符串
func Uint64ToString ¶ added in v0.0.31
Uint64ToString uint64 转换为字符串
func Uint8ToString ¶ added in v0.0.31
Uint8ToString uint8 转换为字符串
func UnmarshalJSON ¶ added in v0.0.21
UnmarshalJSON 将 json 转换为对象
Types ¶
type LossCounter ¶ added in v0.2.7
type LossCounter struct {
// contains filtered or unexported fields
}
func StartLossCounter ¶ added in v0.2.7
func StartLossCounter() *LossCounter
StartLossCounter 开始损耗计数
func (*LossCounter) GetLoss ¶ added in v0.2.7
func (slf *LossCounter) GetLoss(handler func(step int, name string, loss time.Duration))
GetLoss 获取损耗
func (*LossCounter) Record ¶ added in v0.2.7
func (slf *LossCounter) Record(name string)
Record 记录一次损耗
func (*LossCounter) String ¶ added in v0.3.0
func (slf *LossCounter) String() string
type Matcher ¶ added in v0.0.16
type Matcher[Value, Result any] struct { // contains filtered or unexported fields }
Matcher 匹配器
type Permission ¶ added in v0.2.6
type Permission[Code generic.Integer, EntityID comparable] struct { // contains filtered or unexported fields }
func NewPermission ¶ added in v0.2.6
func NewPermission[Code generic.Integer, EntityID comparable]() *Permission[Code, EntityID]
NewPermission 创建权限
func (*Permission[Code, EntityID]) AddPermission ¶ added in v0.2.6
func (slf *Permission[Code, EntityID]) AddPermission(entityId EntityID, permission ...Code)
AddPermission 添加权限
func (*Permission[Code, EntityID]) HasPermission ¶ added in v0.2.6
func (slf *Permission[Code, EntityID]) HasPermission(entityId EntityID, permission Code) bool
HasPermission 是否有权限
func (*Permission[Code, EntityID]) RemovePermission ¶ added in v0.2.6
func (slf *Permission[Code, EntityID]) RemovePermission(entityId EntityID, permission ...Code)
RemovePermission 移除权限
func (*Permission[Code, EntityID]) SetPermission ¶ added in v0.2.6
func (slf *Permission[Code, EntityID]) SetPermission(entityId EntityID, permission ...Code)
SetPermission 设置权限
type StackGo ¶ added in v0.0.13
type StackGo struct {
// contains filtered or unexported fields
}
StackGo 用于获取上一个协程调用的堆栈信息
- 应当最先运行 Wait 函数,然后在其他协程中调用 Stack 函数或者 GiveUp 函数
- 适用于跨协程同步通讯,例如单线程的消息处理统计耗时打印堆栈信息
func (*StackGo) GiveUp ¶ added in v0.0.13
func (slf *StackGo) GiveUp()
GiveUp 放弃收集消息堆栈
- 在调用 Wait 函数后调用该函数,将会放弃收集消息堆栈并且释放资源
- 在调用 GiveUp 函数后调用 Stack 函数,将会 panic
type VerifyHandle ¶ added in v0.0.23
type VerifyHandle[V any] struct { // contains filtered or unexported fields }
VerifyHandle 校验句柄
func Verify ¶ added in v0.0.23
func Verify[V any](handle func(V)) *VerifyHandle[V]
Verify 对特定表达式进行校验,当表达式不成立时,将执行 handle
Example ¶
package main import ( "errors" "fmt" "github.com/kercylan98/minotaur/utils/super" ) func main() { var getId = func() int { return 1 } var n *super.VerifyHandle[int] super.Verify(func(err error) { fmt.Println(err) }).Case(getId() == 1, errors.New("id can't be 1")). Do() super.Verify(func(err error) { fmt.Println(err) }).PreCase(func() bool { return n == nil }, errors.New("n can't be nil"), func(verify *super.VerifyHandle[error]) bool { return verify.Do() }) }
Output: id can't be 1 n can't be nil
func (*VerifyHandle[V]) Case ¶ added in v0.0.23
func (slf *VerifyHandle[V]) Case(expression bool, value V) *VerifyHandle[V]
Case 校验用例,当 expression 成立时,将忽略后续 Case,并将在 Do 时执行 handle,返回 false
func (*VerifyHandle[V]) Do ¶ added in v0.0.23
func (slf *VerifyHandle[V]) Do() bool
Do 执行校验,当校验失败时,将执行 handle,并返回 false
func (*VerifyHandle[V]) PreCase ¶ added in v0.0.23
func (slf *VerifyHandle[V]) PreCase(expression func() bool, value V, caseHandle func(verify *VerifyHandle[V]) bool) bool
PreCase 先决校验用例,当 expression 成立时,将跳过 caseHandle 的执行,直接执行 handle 并返回 false
- 常用于对前置参数的空指针校验,例如当 a 为 nil 时,不执行 a.B(),而是直接返回 false