util

package
v0.0.0-...-6bd00d5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

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
	MUint32
	MUint64
	MStr
	MAny
	Uint16MUint16
	Int32MInt32
	Int32MInt64
	Int64MInt32
	Int64MInt64
	AnyMAny
)
View Source
const (
	Rad2Deg float64 = 180 / math.Pi
	Deg2Rad float64 = math.Pi / 180
	HalfPi  float64 = math.Pi / 2
	Eps     float64 = 1e-5
)
View Source
const (
	Cpu       = "cpu"
	Memory    = "mem"
	Disk      = "disk"
	Goroutine = "goroutine"
)

Variables

View Source
var (
	Ec2Str = map[TErrCode]string{

		EcNil:        "nil",
		EcRecover:    "recover",
		EcServiceErr: "service error",

		EcIo:          "io error",
		EcTimeout:     "timeout",
		EcConnectErr:  "connect error",
		EcListenErr:   "listen error",
		EcAcceptErr:   "accept error",
		EcAddrErr:     "get addr error",
		EcIllegalConn: "illegal conn",
		EcTooManyConn: "too many conn",
		EcWriteFail:   "write fail",
		EcDbErr:       "database error",
		EcRedisErr:    "redis error",

		EcParamsErr:     "params error",
		EcEmpty:         "empty",
		EcTooLong:       "too long",
		EcOutOfRange:    "out of range",
		EcWrongType:     "wrong type",
		EcType:          "error type",
		EcParseErr:      "parse error",
		EcExist:         "exist",
		EcNotExist:      "not exist",
		EcClosed:        "closed",
		EcNotEnough:     "not enough",
		EcNotImplement:  "not implement",
		EcMarshallErr:   "marshall error",
		EcUnmarshallErr: "unmarshall error",
		EcBadHead:       "bad head",
		EcBadPacket:     "bad packet",
		EcEmptyPacket:   "empty packet",
		EcNoAuth:        "no auth",
		EcResFail:       "response fail",
	}

	Ec2Cn = map[TErrCode]string{

		EcNil:        "空引用",
		EcRecover:    "恢复错误",
		EcServiceErr: "服务错误",

		EcIo:          "io错误",
		EcTimeout:     "超时",
		EcConnectErr:  "连接错误",
		EcListenErr:   "监听错误",
		EcAcceptErr:   "接受错误",
		EcAddrErr:     "获取地址错误",
		EcIllegalConn: "非法连接",
		EcTooManyConn: "连接过多",
		EcWriteFail:   "写失败",
		EcDbErr:       "数据库错误",
		EcRedisErr:    "redis错误",

		EcParamsErr:     "参数错误",
		EcEmpty:         "空",
		EcTooLong:       "太长",
		EcOutOfRange:    "越界",
		EcWrongType:     "错误类型",
		EcType:          "错误类型",
		EcParseErr:      "解析错误",
		EcExist:         "已存在",
		EcNotExist:      "不存在",
		EcClosed:        "已关闭",
		EcNotEnough:     "容量不足",
		EcNotImplement:  "未实现",
		EcMarshallErr:   "序列化错误",
		EcUnmarshallErr: "反序列化错误",
		EcBadHead:       "错误的消息头",
		EcBadPacket:     "错误的消息包",
		EcEmptyPacket:   "空包",
		EcNoAuth:        "无权限",
		EcResFail:       "响应错误",
	}
)
View Source
var (
	StackMaxDeep = 8
	LogPrefix    = ".."
)
View Source
var (
	Patterns = []string{
		"/src/",
		".com/",
		".org/",
		".cool/",
		".cn/",
		"/go1.",
	}
)

Functions

func Abs

func Abs(d float64) float64

func AddHttpContentType

func AddHttpContentType(extension string, contentType string)

func AddHttpContentTypes

func AddHttpContentTypes(m map[string]string)

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 float64, bit int32) float64

func CeilInt32

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

func Clamp

func Clamp[T Num](min, max, v T) T

func ClampFloat

func ClampFloat(min, max, v float64) float64

func ClampFloat64

func ClampFloat64(min, max, v float64) float64

func ClampInt

func ClampInt(min, max, v int) int

func ClampInt32

func ClampInt32(min, max, v int32) int32

func Cmp

func Cmp(v1, v2 float64) int

func CmpZero

func CmpZero(v float64) 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 float64) float64

func Equal

func Equal(v1, v2 float64) bool

func ErrCodeToStr

func ErrCodeToStr(ec TErrCode) string

func ExeDir

func ExeDir() string

ExeDir 程序执行目录

func ExeName

func ExeName() string

func Floor

func Floor(d float64, bit int32) float64

func FloorInt32

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

func FormatDur

func FormatDur(d time.Duration) string

func GenMask

func GenMask(items ...int64) int64

func GetDiskPercent

func GetDiskPercent() float64

func GetFreePort

func GetFreePort() (int, error)

func GetHttpContentType

func GetHttpContentType(extension string) string

func GetMemPercent

func GetMemPercent() float64

func GetStack

func GetStack(skip int) []byte

GetStack 优化的堆栈获取函数

func GobMarshal

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

func GobUnmarshal

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

func Haversine

func Haversine(lon1, lat1, lon2, lat2 float64) float64

Haversine 计算经纬度的距离

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 IsInternalIP

func IsInternalIP(ip string) bool

func IsPowerOfTwo

func IsPowerOfTwo(mask int32) bool

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

判断是否为私有地址

func IsVirtualInterface

func IsVirtualInterface(name string) bool

判断是否为虚拟网卡

func JsonConf

func JsonConf() jsoniter.API

func Lerp

func Lerp(from, to, t float64) float64

func LerpFloat

func LerpFloat(v1, v2, v float64) float64

func LerpInt

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

func LogTrim

func LogTrim(file string) string

LogTrim 优化的路径裁剪函数

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 float64) float64

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 float64) float64

func MinInt

func MinInt(a, b int) int

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 NextCap

func NextCap(required, current, slow int) (int, bool)

func NextPowerOfTwo

func NextPowerOfTwo(v int) int

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) float64

PointToSegDist 点到线段的距离

func PointToSegDistSquare

func PointToSegDistSquare(p, a, b Vec2) float64

func PointToVecDist

func PointToVecDist(p, a, b Vec2) float64

func PointToVecDistSquare

func PointToVecDistSquare(p, a, b Vec2) float64

func RadianToDegree

func RadianToDegree(radian float64) float64

func RandStr

func RandStr(n int) string

func RecycleByteBuffer

func RecycleByteBuffer(bf *ByteBuffer)

func RecycleBytes

func RecycleBytes(bytes []byte)

func RecycleCounter

func RecycleCounter(c *Counter)

func ReverseMask

func ReverseMask(mask int64, items *[]int64)

func Round

func Round(d float64, bit int32) float64

func SetErrCodeToStr

func SetErrCodeToStr(ec TErrCode, str string)

func SetErrCodesToStrMap

func SetErrCodesToStrMap(m map[TErrCode]string)

func SetJsonConf

func SetJsonConf(conf jsoniter.Config)

func ShallowCopy

func ShallowCopy(dst, src any)

func ShallowCopyPub

func ShallowCopyPub(dst, src any)

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 int) []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 float64) float64

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 ToLowerCamelCase

func ToLowerCamelCase(s string) string

func ToUnderline

func ToUnderline(str string) string

func ToUpperCamelCase

func ToUpperCamelCase(s string) string

func TriangleArea

func TriangleArea(a, b, c Vec2) float64

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) float64

Vec2Cross 叉积

func Vec2Dist

func Vec2Dist(a, b Vec2) float64

func Vec2DistSquare

func Vec2DistSquare(a, b Vec2) float64

func Vec2Dot

func Vec2Dot(a, b Vec2) float64

Vec2Dot 点积

func Vec2Equal

func Vec2Equal(a, b Vec2) bool

func Vec2Magnitude

func Vec2Magnitude(a Vec2) float64

func Vec2Radian

func Vec2Radian(a, b Vec2) float64

func Vec2ToRadian

func Vec2ToRadian(a Vec2) float64

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 SpawnByteBuffer

func SpawnByteBuffer(c int) *ByteBuffer

func (*ByteBuffer) All

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

func (*ByteBuffer) Available

func (b *ByteBuffer) Available() int

func (*ByteBuffer) Cap

func (b *ByteBuffer) Cap() int

func (*ByteBuffer) Clone

func (b *ByteBuffer) Clone() *ByteBuffer

Clone 克隆缓冲区(深拷贝)

func (*ByteBuffer) Compact

func (b *ByteBuffer) Compact()

Compact 压缩缓冲区,移除已读取的数据

func (*ByteBuffer) CopyBytes

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

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 int)

func (*ByteBuffer) Length

func (b *ByteBuffer) Length() int

func (*ByteBuffer) Pos

func (b *ByteBuffer) Pos() int

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() []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) RInt8

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

func (*ByteBuffer) RInt8s

func (b *ByteBuffer) RInt8s() (v []int8, 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) 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) RMUint32

func (b *ByteBuffer) RMUint32() (m map[string]uint32, err *Err)

func (*ByteBuffer) RMUint64

func (b *ByteBuffer) RMUint64() (m map[string]uint64, 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) RUint8

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

func (*ByteBuffer) RUint8s

func (b *ByteBuffer) RUint8s() (v []uint8, 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) 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) ResetWithCap

func (b *ByteBuffer) ResetWithCap(cap int)

ResetWithCap 重置并预分配指定容量

func (*ByteBuffer) SetPos

func (b *ByteBuffer) SetPos(v int)

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) WInt8

func (b *ByteBuffer) WInt8(v int8)

func (*ByteBuffer) WInt8s

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

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) 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) WMUint32

func (b *ByteBuffer) WMUint32(m map[string]uint32)

func (*ByteBuffer) WMUint64

func (b *ByteBuffer) WMUint64(m map[string]uint64)

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) WUint8

func (b *ByteBuffer) WUint8(v uint8)

func (*ByteBuffer) WUint8s

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

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) 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) WriteBytes

func (b *ByteBuffer) WriteBytes(data ...[]byte)

WriteBytes 批量写入字节数组

func (*ByteBuffer) WriteStrings

func (b *ByteBuffer) WriteStrings(strs ...string)

WriteStrings 批量写入字符串,减少多次扩容

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 BytesToInt

type BytesToInt func([]byte) int

type BytesToInt642Err

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

type BytesToM

type BytesToM func([]byte) M

type BytesToUint16

type BytesToUint16 func([]byte) uint16

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 GetCpuPercent

func GetCpuPercent() (float64, *Err)

func GetInternalIP

func GetInternalIP() (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

NewErr 智能创建错误(使用优化的延迟堆栈)

func NewErrByLevel

func NewErrByLevel(code TErrCode, params M) *Err

NewErrByLevel 根据错误级别创建错误

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 ParseNum

func ParseNum[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

WrapErr 智能包装错误(使用优化的延迟堆栈)

func WrapErrByLevel

func WrapErrByLevel(code TErrCode, e error) *Err

WrapErrByLevel 根据错误级别包装错误

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) Params

func (e *Err) Params() M

func (*Err) Stack

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

Stack 延迟获取堆栈信息

func (*Err) String

func (e *Err) String() string

type ErrLevel

type ErrLevel int

错误级别定义

const (
	// ErrLevelBusiness 业务逻辑错误(不需要堆栈)
	ErrLevelBusiness ErrLevel = iota
	// ErrLevelSystem 系统级错误(需要堆栈)
	ErrLevelSystem
	// ErrLevelCritical 严重错误(需要详细堆栈)
	ErrLevelCritical
)

func GetErrLevel

func GetErrLevel(code TErrCode) ErrLevel

GetErrLevel 获取错误码对应的级别

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)

func (FnBool) Invoke

func (f FnBool) Invoke(b bool)

type FnBoolErr

type FnBoolErr func(bool, *Err)

type FnBytes

type FnBytes func([]byte)

type FnBytes2Bool

type FnBytes2Bool func([]byte, []byte, bool)

type FnBytesSlc

type FnBytesSlc func([][]byte)

type FnE

type FnE func(error)

type FnErr

type FnErr func(*Err)

func (FnErr) Invoke

func (f FnErr) Invoke(err *Err)

type FnErrAny

type FnErrAny func(*Err, []any)

type FnErrCode

type FnErrCode func(TErrCode)

type FnFn

type FnFn func(Fn)

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 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)

func (FnInt64M) Invoke

func (f FnInt64M) Invoke(v int64, m M)

type FnInt64MErr

type FnInt64MErr func(int64, M, *Err)

func (FnInt64MErr) Invoke

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

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 FnInt64Uint16

type FnInt64Uint16 func(int64, uint16)

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 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 FnStrBytesM

type FnStrBytesM func(string, []byte, M)

type FnStrErr

type FnStrErr func(string, *Err)

type FnStrFn

type FnStrFn func(string, Fn)

type FnStrME

type FnStrME func(string, M, error)

type FnStrMErr

type FnStrMErr func(string, M, *Err)

type FnStrSlc

type FnStrSlc func([]string)

type FnStrUint32

type FnStrUint32 func(string, uint32)

type FnUint16

type FnUint16 func(uint16)

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 FnUint162Int642Bytes

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

type IMsg

type IMsg interface {
	ProtoReflect() protoreflect.Message
}

type IResMsg

type IResMsg interface {
	IMsg
	GetCode() int32
	SetCode(code int32)
}

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 Int642ToBool

type Int642ToBool func(int64, int64) bool

type M

type M map[string]any

func (M) Copy

func (m M) Copy() 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) GetB

func (m M) GetB(key string) (bool, bool)

func (M) GetBSlice

func (m M) GetBSlice(key string) ([]bool, bool)

func (M) GetF32

func (m M) GetF32(key string) (float32, bool)

func (M) GetF32Slice

func (m M) GetF32Slice(key string) ([]float32, bool)

func (M) GetF64Slice

func (m M) GetF64Slice(key string) ([]float32, bool)

func (M) GetFloat64

func (m M) GetFloat64(key string) (float64, bool)

func (M) GetI8

func (m M) GetI8(key string) (int8, bool)

func (M) GetI8Slice

func (m M) GetI8Slice(key string) ([]int8, bool)

func (M) GetI16

func (m M) GetI16(key string) (int16, bool)

func (M) GetI16Slice

func (m M) GetI16Slice(key string) ([]int16, bool)

func (M) GetI32

func (m M) GetI32(key string) (int32, bool)

func (M) GetI32Slice

func (m M) GetI32Slice(key string) ([]int32, bool)

func (M) GetI64

func (m M) GetI64(key string) (int64, bool)

func (M) GetI64Slice

func (m M) GetI64Slice(key string) ([]int64, bool)

func (M) GetMI32

func (m M) GetMI32(key string) (map[string]int32, bool)

func (M) GetMI64

func (m M) GetMI64(key string) (map[string]int64, bool)

func (M) GetMU32

func (m M) GetMU32(key string) (map[string]uint32, bool)

func (M) GetMU64

func (m M) GetMU64(key string) (map[string]uint64, bool)

func (M) GetS

func (m M) GetS(key string) (string, bool)

func (M) GetSSlice

func (m M) GetSSlice(key string) ([]string, bool)

func (M) GetU8

func (m M) GetU8(key string) (uint8, bool)

func (M) GetU8Slice

func (m M) GetU8Slice(key string) ([]uint8, bool)

func (M) GetU16

func (m M) GetU16(key string) (uint16, bool)

func (M) GetU16Slice

func (m M) GetU16Slice(key string) ([]uint16, bool)

func (M) GetU32

func (m M) GetU32(key string) (uint32, bool)

func (M) GetU32Slice

func (m M) GetU32Slice(key string) ([]uint32, bool)

func (M) GetU64

func (m M) GetU64(key string) (uint64, bool)

func (M) GetU64Slice

func (m M) GetU64Slice(key string) ([]uint64, bool)

func (M) GetV2

func (m M) GetV2(key string) (Vec2, bool)

func (M) GetV2Slice

func (m M) GetV2Slice(key string) ([]Vec2, bool)

func (M) GetV3

func (m M) GetV3(key string) (Vec3, bool)

func (M) GetV3Slice

func (m M) GetV3Slice(key string) ([]Vec3, 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 MsgToErr

type MsgToErr func(IMsg) *Err

type Num

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

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 Str2BytesToBytesErr

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

type Str2Int64ToBoolBytes

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

type Str162ErrToBytesErr

type Str162ErrToBytesErr func(string, string, *Err) ([]byte, *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 StrToAny

type StrToAny func(string) any

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 = int32
const (
	EcCriticalMin TErrCode = 0

	EcNil        TErrCode = 0 // 空引用
	EcRecover    TErrCode = 1 // 恢复错误
	EcServiceErr TErrCode = 2 // 服务错误

	EcSystemMin TErrCode = 100

	EcIo          TErrCode = 100 // io错误
	EcTimeout     TErrCode = 101 // 超时
	EcConnectErr  TErrCode = 102 // 连接错误
	EcListenErr   TErrCode = 103 // 监听错误
	EcAcceptErr   TErrCode = 104 // 接受错误
	EcAddrErr     TErrCode = 105 // 获取地址错误
	EcIllegalConn TErrCode = 106 // 非法连接
	EcTooManyConn TErrCode = 107 // 连接过多
	EcWriteFail   TErrCode = 108 // 写失败
	EcDbErr       TErrCode = 109 // 数据库错误
	EcRedisErr    TErrCode = 110 // redis错误

	EcBusinessMin TErrCode = 200

	EcParamsErr     TErrCode = 200 // 参数错误
	EcEmpty         TErrCode = 201 // 空
	EcTooLong       TErrCode = 202 // 太长
	EcOutOfRange    TErrCode = 203 // 越界
	EcWrongType     TErrCode = 204 // 错误类型
	EcType          TErrCode = 205 // 错误类型
	EcParseErr      TErrCode = 206 // 解析错误
	EcExist         TErrCode = 207 // 已存在
	EcNotExist      TErrCode = 208 // 不存在
	EcClosed        TErrCode = 209 // 已关闭
	EcNotEnough     TErrCode = 210 // 容量不足
	EcNotImplement  TErrCode = 211 // 未实现
	EcMarshallErr   TErrCode = 212 // 序列化错误
	EcUnmarshallErr TErrCode = 213 // 反序列化错误
	EcBadHead       TErrCode = 214 // 错误的消息头
	EcBadPacket     TErrCode = 215 // 错误的消息包
	EcEmptyPacket   TErrCode = 216 // 空包
	EcNoAuth        TErrCode = 217 // 没有权限
	EcResFail       TErrCode = 218 //响应错误
)

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 float64
	Y float64
}

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 float64) 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 float64) Vec2

func Vec2Lerp

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

func Vec2Mul

func Vec2Mul(a Vec2, v float64) Vec2

func Vec2Normalize

func Vec2Normalize(v Vec2) Vec2

func Vec2One

func Vec2One() Vec2

func Vec2Rotate

func Vec2Rotate(a Vec2, radian float64) Vec2

func Vec2Rotate90

func Vec2Rotate90(a Vec2) Vec2

func Vec2Rotate180

func Vec2Rotate180(v Vec2) Vec2

func Vec2Rotate270

func Vec2Rotate270(a Vec2) Vec2

func Vec2Sub

func Vec2Sub(a, b Vec2) Vec2

func Vec2XRebound

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

func Vec2YRebound

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

type Vec2Int

type Vec2Int struct {
	X int
	Y int
}

func (Vec2Int) Equal

func (v Vec2Int) Equal(v1 Vec2Int) bool

type Vec3

type Vec3 struct {
	X float64
	Y float64
	Z float64
}

func Vec3One

func Vec3One() Vec3

Source Files

  • alias.go
  • any.go
  • bytes_buffer.go
  • cmd.go
  • counter.go
  • ctx.go
  • enable.go
  • err.go
  • err_levels.go
  • gob.go
  • http.go
  • id.go
  • json.go
  • m.go
  • mask.go
  • math.go
  • msg.go
  • net.go
  • num.go
  • path.go
  • pool.go
  • profile.go
  • rand.go
  • slice.go
  • string.go
  • time.go
  • tuple.go
  • vec.go

Jump to

Keyboard shortcuts

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