util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

README

util

Documentation

Index

Constants

View Source
const (
	Bool _BT = iota
	Bools
	Bytes
	Uint8
	Int8
	Int8s
	Uint16
	Uint16s
	Int16
	Int16s
	Int
	Ints
	Uint32
	Uint32s
	Int32
	Int32s
	Uint64
	Uint64s
	Int64
	Int64s
	Float32
	Float32s
	Float64
	Float64s
	Vector2
	Vector2s
	Vector3
	Vector3s
	Str
	Strs
	Time
	Times
	MInt32
	MInt64
	MStr
	MAny
	Uint16MUint16
	Int32MInt32
	Int32MInt64
	Int64MInt32
	Int64MInt64
	AnyMAny
)
View Source
const (
	Rad2Deg float32 = 180 / math.Pi
	Deg2Rad float32 = math.Pi / 180
	HalfPi  float32 = math.Pi / 2
	Eps     float32 = 1e-5
)
View Source
const (
	Cpu       = "cpu"
	Memory    = "mem"
	Disk      = "disk"
	Goroutine = "goroutine"
)

Variables

View Source
var (
	StackMaxDeep = 8
	LogPrefix    = ".."
	LogReg       = regexp.MustCompile(`(\/.+\.(com)|(org))|(\/.+go\d{1}\.\d{1,2}.\d{1,2}|/src)`)
)

Functions

func Abs

func Abs(d float32) float32

func ArgsToSlc

func ArgsToSlc[T any](args ...T) []T

func BytesToInt64

func BytesToInt64(bytes []byte) int64

func BytesToStr

func BytesToStr(b []byte) string

func Cancel

func Cancel()

func Ceil

func Ceil(d float32, bit int32) float32

func CeilInt32

func CeilInt32(ceil, v int32) (r, o int32)

func Clamp

func Clamp(min, max, v float32) float32

func ClampFloat

func ClampFloat(v, min, max float32) float32

func ClampInt32

func ClampInt32(min, max, v int32) int32

func Cmp

func Cmp(v1, v2 float32) int

func CmpZero

func CmpZero(v float32) int

func CopyBytes

func CopyBytes(src []byte) []byte

func Ctx

func Ctx() context.Context

func Default

func Default[T any]() (v T)

func DefaultCmd

func DefaultCmd(m M)

func DegreeToRadian

func DegreeToRadian(angle float32) float32

func Equal

func Equal(v1, v2 float32) bool

func ErrCodeToStr

func ErrCodeToStr(ec TErrCode) string

func ExeName

func ExeName() string

func Floor

func Floor(d float32, bit int32) float32

func FloorInt32

func FloorInt32(floor, v int32) (r, o int32)

func GenMask

func GenMask(items ...int64) int64

func GetDiskPercent

func GetDiskPercent() float64

func GetMemPercent

func GetMemPercent() float64

func GetStack

func GetStack(skip int) []byte

func GobMarshal

func GobMarshal(v any) ([]byte, error)

func GobUnmarshal

func GobUnmarshal(data []byte, v any) error

func Hex

func Hex(bytes []byte) string

func Int64ToBs

func Int64ToBs(id int64) string

func Int64ToBytes

func Int64ToBytes(id int64) []byte

func Int64sToShortStrSlice

func Int64sToShortStrSlice(ids ...int64) []string

func IsLocalIp

func IsLocalIp(ip string) bool

func IsPowerOfTwo

func IsPowerOfTwo(mask int32) bool

func JsonConf

func JsonConf() jsoniter.API

func Lerp

func Lerp(from, to, t float32) float32

func LerpFloat

func LerpFloat(v1, v2, v float32) float32

func LerpInt

func LerpInt(v1, v2, v, t int) int

func LogTrim

func LogTrim(file string) string

func MGet

func MGet[T any](m M, key string) (T, bool)

func MGet2

func MGet2[T any](m M, keys ...string) (T, bool)

func MGetOrSet

func MGetOrSet[T any](m M, key string, new func() T) T

func MPop

func MPop[T any](m M, key string) (T, bool)

func MReplace

func MReplace[T any](m M, key string, val T) (T, bool)

func MUpdate

func MUpdate[T any](m M, key string, fn func(T) T) bool

func MaskAddItem

func MaskAddItem(item, mask int64) int64

func MaskDelItem

func MaskDelItem(item, mask int64) int64

func Max

func Max(l, r float32) float32

func MaxInt

func MaxInt(a, b int) int

func MaxInt32

func MaxInt32(a, b int32) int32

func MaxInt64

func MaxInt64(a, b int64) int64

func MaxUint32

func MaxUint32(a, b uint32) uint32

func MergeUInt32

func MergeUInt32(prevId, lastId uint16) uint32

func Min

func Min(l, r float32) float32

func MinInt32

func MinInt32(a, b int32) int32

func MinInt64

func MinInt64(a, b int64) int64

func MinUint32

func MinUint32(a, b uint32) uint32

func NextPowerOfTwo

func NextPowerOfTwo(v uint32) uint32

func PbMarshal

func PbMarshal(pkt IMsg) ([]byte, error)

func PbUnmarshal

func PbUnmarshal(data []byte, pkt IMsg) error

func PointInTriangle

func PointInTriangle(p, a, b, c Vec2) bool

func PointOnSeg

func PointOnSeg(p, a, b Vec2) bool

PointOnSeg 点是否在线段上

func PointToSegDist

func PointToSegDist(p, a, b Vec2) float32

PointToSegDist 点到线段的距离

func PointToSegDistSquare

func PointToSegDistSquare(p, a, b Vec2) float32

func PointToVecDist

func PointToVecDist(p, a, b Vec2) float32

func PointToVecDistSquare

func PointToVecDistSquare(p, a, b Vec2) float32

func RadianToDegree

func RadianToDegree(radian float32) float32

func RandStr

func RandStr(n int) string

func RecycleBytes

func RecycleBytes(bytes []byte)

func RecycleCounter

func RecycleCounter(c *Counter)

func Round

func Round(d float32, bit int32) float32

func SetErrCodeToStr

func SetErrCodeToStr(ec TErrCode, str string)

func SetExeDir

func SetExeDir(dir string)

SetExeDir 手动指定执行目录

func SetJsonConf

func SetJsonConf(conf jsoniter.Config)

func ShortStrToInt64

func ShortStrToInt64(id string) int64

func ShortStrToUint16

func ShortStrToUint16(id string) uint16

func ShortStrToUint32

func ShortStrToUint32(id string) uint32

func ShortStrToUint64

func ShortStrToUint64(id string) uint64

func SpawnBytes

func SpawnBytes() []byte

func SpawnBytesWithLen

func SpawnBytesWithLen(l uint32) []byte

func SplitSlc1

func SplitSlc1[T any](slc []any) T

func SplitSlc2

func SplitSlc2[T1, T2 any](slc []any) (T1, T2)

func SplitSlc3

func SplitSlc3[T1, T2, T3 any](slc []any) (T1, T2, T3)

func SplitSlc4

func SplitSlc4[T1, T2, T3, T4 any](slc []any) (T1, T2, T3, T4)

func SplitSlc5

func SplitSlc5[T1, T2, T3, T4, T5 any](slc []any) (T1, T2, T3, T4, T5)

func SplitSlc6

func SplitSlc6[T1, T2, T3, T4, T5, T6 any](slc []any) (T1, T2, T3, T4, T5, T6)

func SplitSlc7

func SplitSlc7[T1, T2, T3, T4, T5, T6, T7 any](slc []any) (T1, T2, T3, T4, T5, T6, T7)

func SplitSlc8

func SplitSlc8[T1, T2, T3, T4, T5, T6, T7, T8 any](slc []any) (T1, T2, T3, T4, T5, T6, T7, T8)

func SplitUInt32

func SplitUInt32(code uint32) (prevId, lastId uint16)

func SplitWords

func SplitWords(str string, words *[]string)

func Sqrt

func Sqrt(v float32) float32

func StartProfile

func StartProfile(dur time.Duration, receiver chan<- M)

func StrToBytes

func StrToBytes(s string) []byte

func StringsJoin

func StringsJoin(sep string, slc ...string) string

func TestMask

func TestMask(item, mask int64) bool

func ToBigHump

func ToBigHump(str string) string

func ToUnderline

func ToUnderline(str string) string

func TriangleArea

func TriangleArea(a, b, c Vec2) float32

TriangleArea 三点构成的三角形面积

func Uint16ToShortStr

func Uint16ToShortStr(id uint16) string

func Uint32ToShortStr

func Uint32ToShortStr(id uint32) string

func Uint64ToShortStr

func Uint64ToShortStr(id uint64) string

func Vec2Cross

func Vec2Cross(a, b Vec2) float32

Vec2Cross 叉积

func Vec2Dist

func Vec2Dist(a, b Vec2) float32

func Vec2DistSquare

func Vec2DistSquare(a, b Vec2) float32

func Vec2Dot

func Vec2Dot(a, b Vec2) float32

Vec2Dot 点积

func Vec2Equal

func Vec2Equal(a, b Vec2) bool

func Vec2Magnitude

func Vec2Magnitude(a Vec2) float32

func Vec2Radian

func Vec2Radian(a, b Vec2) float32

func Vec2ToRadian

func Vec2ToRadian(a Vec2) float32

func WorkDir

func WorkDir() string

WorkDir 程序执行目录

Types

type AnyBoolToAnyBool

type AnyBoolToAnyBool func(any, bool) (any, bool)

type AnyBoolToBool

type AnyBoolToBool func(any, bool) bool

type AnyErrToBool

type AnyErrToBool func(any, *Err) bool

type AnyToAny

type AnyToAny func(any) any

type AnyToAnyBool

type AnyToAnyBool func(any) (any, bool)

type AnyToBool

type AnyToBool func(any) bool

type AnyToBytesError

type AnyToBytesError func(any) ([]byte, error)

type AnyToErr

type AnyToErr func(any) *Err

type AnyToInt64

type AnyToInt64 func(any) int64

type BoolToErr

type BoolToErr func(bool) *Err

type ByteBuffer

type ByteBuffer struct {
	// contains filtered or unexported fields
}

func (*ByteBuffer) All

func (b *ByteBuffer) All() []byte

func (*ByteBuffer) Available

func (b *ByteBuffer) Available() uint32

func (*ByteBuffer) Cap

func (b *ByteBuffer) Cap() uint32

func (*ByteBuffer) CopyBytes

func (b *ByteBuffer) CopyBytes() ([]byte, uint32)

func (*ByteBuffer) Dispose

func (b *ByteBuffer) Dispose()

Dispose 释放后不要再使用数据

func (*ByteBuffer) InitBytes

func (b *ByteBuffer) InitBytes(bytes []byte)

func (*ByteBuffer) InitCap

func (b *ByteBuffer) InitCap(c uint32)

func (*ByteBuffer) Length

func (b *ByteBuffer) Length() uint32

func (*ByteBuffer) Pos

func (b *ByteBuffer) Pos() uint32

func (*ByteBuffer) RAny

func (b *ByteBuffer) RAny() (v any, err *Err)

func (*ByteBuffer) RAnyMAny

func (b *ByteBuffer) RAnyMAny(m map[any]any) (err *Err)

func (*ByteBuffer) RAvailable

func (b *ByteBuffer) RAvailable() (v []byte)

RAvailable 读取剩余所有字节

func (*ByteBuffer) RBool

func (b *ByteBuffer) RBool() (v bool, err *Err)

func (*ByteBuffer) RBools

func (b *ByteBuffer) RBools() (v []bool, err *Err)

func (*ByteBuffer) RBytes

func (b *ByteBuffer) RBytes() ([]byte, *Err)

func (*ByteBuffer) RErr

func (b *ByteBuffer) RErr() (e *Err, re *Err)

func (*ByteBuffer) RFloat32

func (b *ByteBuffer) RFloat32() (v float32, err *Err)

func (*ByteBuffer) RFloat32s

func (b *ByteBuffer) RFloat32s() (v []float32, err *Err)

func (*ByteBuffer) RFloat64

func (b *ByteBuffer) RFloat64() (v float64, err *Err)

func (*ByteBuffer) RFloat64s

func (b *ByteBuffer) RFloat64s() (v []float64, err *Err)

func (*ByteBuffer) RInt

func (b *ByteBuffer) RInt() (v int, err *Err)

func (*ByteBuffer) RInt16

func (b *ByteBuffer) RInt16() (v int16, err *Err)

func (*ByteBuffer) RInt16s

func (b *ByteBuffer) RInt16s() (v []int16, err *Err)

func (*ByteBuffer) RInt32

func (b *ByteBuffer) RInt32() (v int32, err *Err)

func (*ByteBuffer) RInt32MInt32

func (b *ByteBuffer) RInt32MInt32() (m map[int32]int32, err *Err)

func (*ByteBuffer) RInt32MInt64

func (b *ByteBuffer) RInt32MInt64() (m map[int32]int64, err *Err)

func (*ByteBuffer) RInt32s

func (b *ByteBuffer) RInt32s() (v []int32, err *Err)

func (*ByteBuffer) RInt64

func (b *ByteBuffer) RInt64() (v int64, err *Err)

func (*ByteBuffer) RInt64MInt32

func (b *ByteBuffer) RInt64MInt32() (m map[int64]int32, err *Err)

func (*ByteBuffer) RInt64MInt64

func (b *ByteBuffer) RInt64MInt64() (m map[int64]int64, err *Err)

func (*ByteBuffer) RInt64s

func (b *ByteBuffer) RInt64s() (v []int64, err *Err)

func (*ByteBuffer) RInt8

func (b *ByteBuffer) RInt8() (v int8, err *Err)

func (*ByteBuffer) RInt8s

func (b *ByteBuffer) RInt8s() (v []int8, err *Err)

func (*ByteBuffer) RInts

func (b *ByteBuffer) RInts() (v []int, err *Err)

func (*ByteBuffer) RJson

func (b *ByteBuffer) RJson(v any) *Err

func (*ByteBuffer) RMAny

func (b *ByteBuffer) RMAny(m M) (err *Err)

func (*ByteBuffer) RMInt32

func (b *ByteBuffer) RMInt32() (m map[string]int32, err *Err)

func (*ByteBuffer) RMInt64

func (b *ByteBuffer) RMInt64() (m map[string]int64, err *Err)

func (*ByteBuffer) RMStr

func (b *ByteBuffer) RMStr() (m MS, err *Err)

func (*ByteBuffer) RShortString

func (b *ByteBuffer) RShortString() (v string, err *Err)

func (*ByteBuffer) RString

func (b *ByteBuffer) RString() (v string, err *Err)

func (*ByteBuffer) RStringNoLen

func (b *ByteBuffer) RStringNoLen() (v string)

func (*ByteBuffer) RStrings

func (b *ByteBuffer) RStrings() (v []string, err *Err)

func (*ByteBuffer) RUint16

func (b *ByteBuffer) RUint16() (v uint16, err *Err)

func (*ByteBuffer) RUint16MUint16

func (b *ByteBuffer) RUint16MUint16() (m map[uint16]uint16, err *Err)

func (*ByteBuffer) RUint16s

func (b *ByteBuffer) RUint16s() (v []uint16, err *Err)

func (*ByteBuffer) RUint32

func (b *ByteBuffer) RUint32() (v uint32, err *Err)

func (*ByteBuffer) RUint32s

func (b *ByteBuffer) RUint32s() (v []uint32, err *Err)

func (*ByteBuffer) RUint64

func (b *ByteBuffer) RUint64() (v uint64, err *Err)

func (*ByteBuffer) RUint64s

func (b *ByteBuffer) RUint64s() (v []uint64, err *Err)

func (*ByteBuffer) RUint8

func (b *ByteBuffer) RUint8() (v uint8, err *Err)

func (*ByteBuffer) RUint8s

func (b *ByteBuffer) RUint8s() (v []uint8, err *Err)

func (*ByteBuffer) RVec2

func (b *ByteBuffer) RVec2() (v Vec2, err *Err)

func (*ByteBuffer) RVec2s

func (b *ByteBuffer) RVec2s() (v []Vec2, err *Err)

func (*ByteBuffer) RVec3

func (b *ByteBuffer) RVec3() (v Vec3, err *Err)

func (*ByteBuffer) RVec3s

func (b *ByteBuffer) RVec3s() (v []Vec3, err *Err)

func (*ByteBuffer) Read

func (b *ByteBuffer) Read(p []byte) (n int, err error)

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset()

func (*ByteBuffer) SetPos

func (b *ByteBuffer) SetPos(v uint32)

func (*ByteBuffer) ToHex

func (b *ByteBuffer) ToHex() string

func (*ByteBuffer) WAny

func (b *ByteBuffer) WAny(v any) *Err

func (*ByteBuffer) WAny2

func (b *ByteBuffer) WAny2(m map[any]any) (err *Err)

func (*ByteBuffer) WAnyMAny

func (b *ByteBuffer) WAnyMAny(m map[any]any) *Err

func (*ByteBuffer) WBool

func (b *ByteBuffer) WBool(v bool)

func (*ByteBuffer) WBools

func (b *ByteBuffer) WBools(v []bool)

func (*ByteBuffer) WBytes

func (b *ByteBuffer) WBytes(v []byte)

func (*ByteBuffer) WErr

func (b *ByteBuffer) WErr(err *Err) *Err

func (*ByteBuffer) WFloat32

func (b *ByteBuffer) WFloat32(v float32)

func (*ByteBuffer) WFloat32s

func (b *ByteBuffer) WFloat32s(v []float32)

func (*ByteBuffer) WFloat64

func (b *ByteBuffer) WFloat64(v float64)

func (*ByteBuffer) WFloat64s

func (b *ByteBuffer) WFloat64s(v []float64)

func (*ByteBuffer) WInt

func (b *ByteBuffer) WInt(v int)

func (*ByteBuffer) WInt16

func (b *ByteBuffer) WInt16(v int16)

func (*ByteBuffer) WInt16s

func (b *ByteBuffer) WInt16s(v []int16)

func (*ByteBuffer) WInt32

func (b *ByteBuffer) WInt32(v int32)

func (*ByteBuffer) WInt32MInt32

func (b *ByteBuffer) WInt32MInt32(m map[int32]int32)

func (*ByteBuffer) WInt32MInt64

func (b *ByteBuffer) WInt32MInt64(m map[int32]int64)

func (*ByteBuffer) WInt32s

func (b *ByteBuffer) WInt32s(v []int32)

func (*ByteBuffer) WInt64

func (b *ByteBuffer) WInt64(v int64)

func (*ByteBuffer) WInt64MInt32

func (b *ByteBuffer) WInt64MInt32(m map[int64]int32)

func (*ByteBuffer) WInt64MInt64

func (b *ByteBuffer) WInt64MInt64(m map[int64]int64)

func (*ByteBuffer) WInt64s

func (b *ByteBuffer) WInt64s(v []int64)

func (*ByteBuffer) WInt8

func (b *ByteBuffer) WInt8(v int8)

func (*ByteBuffer) WInt8s

func (b *ByteBuffer) WInt8s(v []int8)

func (*ByteBuffer) WInts

func (b *ByteBuffer) WInts(v []int)

func (*ByteBuffer) WJson

func (b *ByteBuffer) WJson(o any) *Err

func (*ByteBuffer) WMAny

func (b *ByteBuffer) WMAny(m M) *Err

func (*ByteBuffer) WMInt32

func (b *ByteBuffer) WMInt32(m map[string]int32)

func (*ByteBuffer) WMInt64

func (b *ByteBuffer) WMInt64(m map[string]int64)

func (*ByteBuffer) WMStr

func (b *ByteBuffer) WMStr(m MS)

func (*ByteBuffer) WShortString

func (b *ByteBuffer) WShortString(v string)

func (*ByteBuffer) WString

func (b *ByteBuffer) WString(v string)

func (*ByteBuffer) WStringNoLen

func (b *ByteBuffer) WStringNoLen(v string)

func (*ByteBuffer) WStrings

func (b *ByteBuffer) WStrings(v []string)

func (*ByteBuffer) WUint16

func (b *ByteBuffer) WUint16(v uint16)

func (*ByteBuffer) WUint16MUint16

func (b *ByteBuffer) WUint16MUint16(m map[uint16]uint16)

func (*ByteBuffer) WUint16s

func (b *ByteBuffer) WUint16s(v []uint16)

func (*ByteBuffer) WUint32

func (b *ByteBuffer) WUint32(v uint32)

func (*ByteBuffer) WUint32s

func (b *ByteBuffer) WUint32s(v []uint32)

func (*ByteBuffer) WUint64

func (b *ByteBuffer) WUint64(v uint64)

func (*ByteBuffer) WUint64s

func (b *ByteBuffer) WUint64s(v []uint64)

func (*ByteBuffer) WUint8

func (b *ByteBuffer) WUint8(v uint8)

func (*ByteBuffer) WUint8s

func (b *ByteBuffer) WUint8s(v []uint8)

func (*ByteBuffer) WVec2

func (b *ByteBuffer) WVec2(v Vec2)

func (*ByteBuffer) WVec2s

func (b *ByteBuffer) WVec2s(v []Vec2)

func (*ByteBuffer) WVec3

func (b *ByteBuffer) WVec3(v Vec3)

func (*ByteBuffer) WVec3s

func (b *ByteBuffer) WVec3s(v []Vec3)

func (*ByteBuffer) Write

func (b *ByteBuffer) Write(v []byte) (int, error)

func (*ByteBuffer) WriteTo

func (b *ByteBuffer) WriteTo(writer io.Writer) (n int, err error)

type BytesAnyToErr

type BytesAnyToErr func([]byte, any) *Err

type BytesAnyToError

type BytesAnyToError func([]byte, any) error

type BytesToAnyErr

type BytesToAnyErr func([]byte) (any, *Err)

type BytesToBytes

type BytesToBytes func([]byte) []byte

type BytesToErr

type BytesToErr func([]byte) *Err

type BytesToInt642Err

type BytesToInt642Err func([]byte) (int64, int64, *Err)

type BytesToM

type BytesToM func([]byte) M

type BytesToUint16

type BytesToUint16 func([]byte) uint16

type BytesToUint32

type BytesToUint32 func([]byte) uint32

type CmdHandler

type CmdHandler[T any] func(T, any) *Err

type Command

type Command[T any] struct {
	// contains filtered or unexported fields
}

func Cmd

func Cmd() *Command[M]

func NewCommand

func NewCommand[T any](data T) *Command[T]

func (*Command[T]) Bind

func (c *Command[T]) Bind(name string, handler CmdHandler[T])

func (*Command[T]) Data

func (c *Command[T]) Data() T

func (*Command[T]) Process

func (c *Command[T]) Process(name string, data any) *Err

func (*Command[T]) Unbind

func (c *Command[T]) Unbind(name string) bool

type Compare

type Compare[T any] func(v1, v2 T) int

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter(total uint32) *Counter

func SpawnCounter

func SpawnCounter(total uint32) *Counter

func (*Counter) Add

func (c *Counter) Add(v uint32) (uint32, bool)

func (*Counter) Count

func (c *Counter) Count() uint32

func (*Counter) Reset

func (c *Counter) Reset(total uint32)

func (*Counter) Total

func (c *Counter) Total() uint32

type Enable

type Enable struct {
	Mtx sync.RWMutex
	// contains filtered or unexported fields
}

func NewEnable

func NewEnable() *Enable

func (*Enable) Disable

func (e *Enable) Disable(fn FnAnySlc, params ...any) bool

func (*Enable) Disabled

func (e *Enable) Disabled() bool

func (*Enable) Enable

func (e *Enable) Enable(fn FnAnySlc, params ...any) bool

func (*Enable) IfDisable

func (e *Enable) IfDisable(fn Fn) (ok bool)

func (*Enable) IfEnable

func (e *Enable) IfEnable(fn Fn) (ok bool)

func (*Enable) RAction

func (e *Enable) RAction(fn FnAnySlc, params ...any) *Err

func (*Enable) WAction

func (e *Enable) WAction(fn FnAnySlc, params ...any) *Err

func (*Enable) WAction2

func (e *Enable) WAction2(fn Fn) *Err

type Err

type Err struct {
	// contains filtered or unexported fields
}

func CheckLocalIp

func CheckLocalIp(ip string) (string, *Err)

func GetCpuPercent

func GetCpuPercent() (float64, *Err)

func GetLocalIp

func GetLocalIp() (string, *Err)

func JsonMarshal

func JsonMarshal(o any) ([]byte, *Err)

func JsonMarshalIndent

func JsonMarshalIndent(o any, prefix, indent string) ([]byte, *Err)

func JsonUnmarshal

func JsonUnmarshal(bytes []byte, o any) *Err

func NewErr

func NewErr(code TErrCode, params M) *Err

func NewErrWithStack

func NewErrWithStack(code TErrCode, stack []byte, params M) *Err

func NewM

func NewM(bytes []byte, m M) *Err

func NewNoStackErr

func NewNoStackErr(code TErrCode, params M) *Err

func ParseAddrPort

func ParseAddrPort(addr string) (int, *Err)

func ParseInt

func ParseInt[T Num](s string) (v T, err *Err)

func SplitInt64

func SplitInt64(sep, str string) ([]int64, *Err)

func SplitUint16

func SplitUint16(sep, str string) ([]uint16, *Err)

func WrapErr

func WrapErr(code TErrCode, e error) *Err

func (*Err) AddParam

func (e *Err) AddParam(k string, v any)

func (*Err) AddParams

func (e *Err) AddParams(params M)

func (*Err) Code

func (e *Err) Code() TErrCode

func (*Err) Error

func (e *Err) Error() string

func (*Err) GetParam

func (e *Err) GetParam(k string) (v any, ok bool)

func (*Err) IsNoStack

func (e *Err) IsNoStack() bool

func (*Err) Params

func (e *Err) Params() M

func (*Err) Stack

func (e *Err) Stack() []byte

func (*Err) String

func (e *Err) String() string

func (*Err) ToBytes

func (e *Err) ToBytes() []byte

func (*Err) UpdateParam

func (e *Err) UpdateParam(k string, action AnyBoolToAnyBool)

type Fn

type Fn func()

func (Fn) Invoke

func (f Fn) Invoke()

type FnAny

type FnAny func(any)

type FnAnyErr

type FnAnyErr func(any, *Err)

type FnAnySlc

type FnAnySlc func([]any)

type FnAnySlc2

type FnAnySlc2 func(...any)

type FnBool

type FnBool func(bool)

type FnBoolErr

type FnBoolErr func(bool, *Err)

type FnBytes

type FnBytes func([]byte)

type FnBytesSlc

type FnBytesSlc func([][]byte)

type FnErr

type FnErr func(*Err)

func (FnErr) Invoke

func (f FnErr) Invoke(err *Err)

type FnInt

type FnInt func(int)

type FnInt32

type FnInt32 func(int32)

type FnInt64

type FnInt64 func(int64)

func (FnInt64) Invoke

func (f FnInt64) Invoke(v int64)

type FnInt642

type FnInt642 func(int64, int64)

func (FnInt642) Invoke

func (f FnInt642) Invoke(v1, v2 int64)

type FnInt642Any

type FnInt642Any func(int64, int64, any)

type FnInt642Bool

type FnInt642Bool func(int64, int64, bool)

type FnInt642Err

type FnInt642Err func(int64, int64, *Err)

type FnInt643

type FnInt643 func(int64, int64, int64)

type FnInt64Any

type FnInt64Any func(int64, any)

func (FnInt64Any) Invoke

func (f FnInt64Any) Invoke(v int64, obj any)

type FnInt64Bool

type FnInt64Bool func(int64, bool)

type FnInt64Bytes

type FnInt64Bytes func(int64, []byte)

type FnInt64Err

type FnInt64Err func(int64, *Err)

func (FnInt64Err) Invoke

func (f FnInt64Err) Invoke(v int64, err *Err)

type FnInt64M

type FnInt64M func(int64, M)

type FnInt64MBytes

type FnInt64MBytes func(int64, M, []byte)

type FnInt64MErr

type FnInt64MErr func(int64, M, *Err)

func (FnInt64MErr) Invoke

func (f FnInt64MErr) Invoke(v int64, head M, err *Err)

type FnInt64MMsg

type FnInt64MMsg func(int64, M, IMsg)

func (FnInt64MMsg) Invoke

func (f FnInt64MMsg) Invoke(v int64, head M, obj IMsg)

type FnInt64MUint16

type FnInt64MUint16 func(int64, M, uint16)

type FnInt64Str

type FnInt64Str func(int64, string)

func (FnInt64Str) Invoke

func (f FnInt64Str) Invoke(v int64, str string)

type FnInt64StrBool

type FnInt64StrBool func(int64, string, bool)

type FnIntAnySlc

type FnIntAnySlc func(int, []any)

type FnIntAnySlc2

type FnIntAnySlc2 func(int, []any, []any)

type FnM

type FnM func(M)

type FnM2Bool

type FnM2Bool func(M, M, bool)

type FnMAny

type FnMAny func(M, any)

type FnMBool

type FnMBool func(M, bool)

type FnMErr

type FnMErr func(M, *Err)

type FnMUint32

type FnMUint32 func(M, uint32)

type FnMapBool

type FnMapBool func(map[string]bool)

type FnMsg

type FnMsg func(IMsg)

type FnStr

type FnStr func(string)

func (FnStr) Invoke

func (f FnStr) Invoke(str string)

type FnStr2Bool

type FnStr2Bool func(string, string, bool)

type FnStrAny

type FnStrAny func(string, any)

type FnStrBool

type FnStrBool func(string, bool)

type FnStrBytes

type FnStrBytes func(string, []byte)

type FnStrErr

type FnStrErr func(string, *Err)

type FnStrFn

type FnStrFn func(string, Fn)

type FnStrSlc

type FnStrSlc func([]string)

type FnUint16

type FnUint16 func(uint16)

type FnUint162Int642Bytes

type FnUint162Int642Bytes func(uint16, uint16, int64, int64, []byte)

type FnUint16Bool

type FnUint16Bool func(uint16, bool)

type FnUint16Bytes

type FnUint16Bytes func(uint16, []byte)

type FnUint16Err

type FnUint16Err func(uint16, *Err)

type FnUint16Int642Bytes

type FnUint16Int642Bytes func(uint16, int64, int64, []byte)

type FnUint32

type FnUint32 func(uint32)

type IMsg

type IMsg interface {
	ProtoReflect() protoreflect.Message
}

type Id

type Id interface {
	int32 | uint32 | int64 | uint64 | string
}

type Int64AnyToBool

type Int64AnyToBool func(int64, any) bool

type Int64ToBool

type Int64ToBool func(int64) bool

type Int64ToErrCode

type Int64ToErrCode func(int64) TErrCode

type Int64ToInt64

type Int64ToInt64 func(int64) int64

type Int64ToInt64Err

type Int64ToInt64Err func(int64) (int64, *Err)

type Int64ToStr

type Int64ToStr func(int64) string

type Int64ToStrErr

type Int64ToStrErr func(int64) (string, *Err)

type M

type M map[string]any

func (M) Copy

func (m M) Copy(toM M) M

func (M) CopyTo

func (m M) CopyTo(n M)

func (M) Del

func (m M) Del(key string)

func (M) FromBytes

func (m M) FromBytes(bytes []byte) *Err

func (M) FromGob

func (m M) FromGob(bytes []byte) *Err

func (M) FromJson

func (m M) FromJson(bytes []byte) *Err

func (M) Get

func (m M) Get(key string) (any, bool)

func (M) Has

func (m M) Has(key string) (ok bool)

func (M) IndentJson

func (m M) IndentJson() []byte

func (M) MustGet

func (m M) MustGet(key string, def any) any

func (M) Replace

func (m M) Replace(key string, val any) (oldVal any, ok bool)

func (M) Set

func (m M) Set(key string, val any)

func (M) Set2

func (m M) Set2(val any, keys ...string) *Err

func (M) ToBytes

func (m M) ToBytes() ([]byte, *Err)

func (M) ToGob

func (m M) ToGob() ([]byte, *Err)

func (M) ToJson

func (m M) ToJson() ([]byte, *Err)

func (M) ToSlice

func (m M) ToSlice(slc *[]any)

func (M) Update

func (m M) Update(key string, action AnyToAny) (ok bool)

type M32

type M32 map[string]int32

type M64

type M64 map[string]int64

type MF32

type MF32 map[string]float32

type MF64

type MF64 map[string]float64

type MS

type MS map[string]string

type MToAny

type MToAny func(M) any

type MToBool

type MToBool func(M) bool

type MToBytes

type MToBytes func(M) []byte

type MToErr

type MToErr func(M) *Err

type MToInt64

type MToInt64 func(M) int64

type Num

type Num interface {
	~int16 | ~uint16 | ~int32 | ~uint32 | ~int64 | ~uint64
}

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool[T any](opts ...PoolOption[T]) *Pool[T]

func (*Pool[T]) Push

func (p *Pool[T]) Push(value T)

func (*Pool[T]) Shift

func (p *Pool[T]) Shift() (v T)

type PoolOption

type PoolOption[T any] func(o *poolOption[T])

func PoolMaxCap

func PoolMaxCap[T any](c int) PoolOption[T]

func PoolMinCap

func PoolMinCap[T any](c int) PoolOption[T]

func PoolSpawn

func PoolSpawn[T any](spawn func() T) PoolOption[T]

type Str162ErrToBytesErr

type Str162ErrToBytesErr func(string, string, *Err) ([]byte, *Err)

type Str2BytesToBytesErr

type Str2BytesToBytesErr func(string, string, []byte) ([]byte, *Err)

type Str2Int64ToBoolBytes

type Str2Int64ToBoolBytes func(string, string, int64) (bool, *Err)

type StrAnyToErr

type StrAnyToErr func(string, any) *Err

type StrBytesToBool

type StrBytesToBool func(string, []byte) bool

type StrFnToErr

type StrFnToErr func(string, Fn) *Err

type StrInt64ToBool

type StrInt64ToBool func(string, int64) *Err

type StrIntToBool

type StrIntToBool func(string, int) *Err

type StrToBool

type StrToBool func(string) bool

type StrToBytesErr

type StrToBytesErr func(string) ([]byte, *Err)

type StrToStr

type StrToStr func(string) string

type StrToStr2Err

type StrToStr2Err func(string) (string, string, *Err)

type TErrCode

type TErrCode = uint16
const (
	EcMin TErrCode = iota + 60000
	EcNil
	EcRecover
	EcWrongType
	EcBusy
	EcNotEnough
	EcNoAuth
	EcTimeout
	EcClosed
	EcOpened
	EcEmpty
	EcBadHead
	EcBadPacket
	EcExist
	EcNotExist
	EcMarshallErr
	EcUnmarshallErr
	EcIllegalOp
	EcIllegalConn
	EcTooManyConn
	EcParamsErr
	EcParseErr
	EcIo
	EcOutOfRange
	EcTooLong
	EcTooMuch
	EcLengthErr
	EcNotExistAgent
	EcSendErr
	EcReceiveErr
	EcAcceptErr
	EcConnectErr
	EcListenErr
	EcAddrErr
	EcUnavailable
	EcNotImplement
	EcType
	EcWriteFail
	EcFail
	EcTooSlow
	EcServiceErr
	EcDbErr
	EcRedisErr
	EcEtcdErr
)

type ToAny

type ToAny func() any

type ToBool

type ToBool func() bool

type ToErr

type ToErr func() *Err

type ToErrCode

type ToErrCode func() TErrCode

type ToFnInt64Fn

type ToFnInt64Fn func() FnStrFn

type ToInt64

type ToInt64 func() int64

type ToM

type ToM func() M

type ToMsg

type ToMsg func() IMsg

type ToStr

type ToStr func() string

type ToStrBool

type ToStrBool func() (string, bool)

type Tuple2

type Tuple2[T1, T2 any] struct {
	Item1 T1
	Item2 T2
}

type Tuple3

type Tuple3[T1, T2, T3 any] struct {
	Item1 T1
	Item2 T2
	Item3 T3
}

type Tuple4

type Tuple4[T1, T2, T3, T4 any] struct {
	Item1 T1
	Item2 T2
	Item3 T3
	Item4 T4
}

type Tuple5

type Tuple5[T1, T2, T3, T4, T5 any] struct {
	Item1 T1
	Item2 T2
	Item3 T3
	Item4 T4
	Item5 T5
}

type Uint16Int64ToUint16

type Uint16Int64ToUint16 func(uint16, int64) uint16

type Uint16ToBool

type Uint16ToBool func(uint16) bool

type Vec2

type Vec2 struct {
	X float32
	Y float32
}

func PointToSegNearPoint

func PointToSegNearPoint(p, a, b Vec2) Vec2

func PointToVecNearPoint

func PointToVecNearPoint(p, a, b Vec2) Vec2

func RandDir

func RandDir() Vec2

func RandRange

func RandRange(center Vec2, radius float32) Vec2

func Vec2Add

func Vec2Add(a, b Vec2) Vec2

func Vec2Clamp

func Vec2Clamp(v, min, max Vec2) Vec2

func Vec2Div

func Vec2Div(a Vec2, v float32) Vec2

func Vec2Lerp

func Vec2Lerp(a, b Vec2, v float32) Vec2

func Vec2Mul

func Vec2Mul(a Vec2, v float32) Vec2

func Vec2Normalize

func Vec2Normalize(v Vec2) Vec2

func Vec2One

func Vec2One() Vec2

func Vec2Rotate

func Vec2Rotate(a Vec2, radian float32) Vec2

func Vec2Rotate180

func Vec2Rotate180(v Vec2) Vec2

func Vec2Rotate270

func Vec2Rotate270(a Vec2) Vec2

func Vec2Rotate90

func Vec2Rotate90(a Vec2) Vec2

func Vec2Sub

func Vec2Sub(a, b Vec2) Vec2

func Vec2XRebound

func Vec2XRebound(a, b Vec2, bound float32) (Vec2, bool)

func Vec2YRebound

func Vec2YRebound(a, b Vec2, bound float32) (Vec2, bool)

type Vec2Int

type Vec2Int struct {
	X int32
	Y int32
}

func (Vec2Int) Equal

func (v Vec2Int) Equal(v1 Vec2Int) bool

type Vec3

type Vec3 struct {
	X float32
	Y float32
	Z float32
}

func Vec3One

func Vec3One() Vec3

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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