Documentation ¶
Index ¶
- func BoolToString(value bool) string
- func ByteToString(value byte) string
- func BytesToString(b []byte) string
- func Convert[A, B any](src A) B
- func Float32ToString(value float32) string
- func Float64ToString(value float64) string
- func GetErrorCode(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 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 MarshalIndentJSON(v interface{}, prefix, indent string) []byte
- func MarshalJSON(v interface{}) []byte
- 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 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 Matcher
- 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 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 GetErrorCode ¶ added in v0.0.18
GetErrorCode 通过错误引用获取错误码,如果错误不存在则返回 0
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 RegErrorRef ¶ added in v0.0.20
RegErrorRef 通过错误码注册错误,返回错误的引用
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 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 Matcher ¶ added in v0.0.16
type Matcher[Value, Result any] struct { // contains filtered or unexported fields }
Matcher 匹配器
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