util

package
v0.0.0-...-2692626 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GRunMode = RunModeRelease

GRunMode 运行模式

Functions

func Command

func Command(args string) (outStr string, errStr string, err error)

Command 调用 linux 命令

参数:
	args:"chmod +x /xx/xx/x.sh"

func GenNORepeatIdx

func GenNORepeatIdx(set map[uint32]struct{}, uint32Slice []uint32) (int, error)

GenNORepeatIdx 生成 不重复 序号

参数:
	set:已有数据
	uint32Slice:从该slice中随机一个,与set中不重复
返回值:
	unit32Slice 中的index

func GenRandValue

func GenRandValue(except uint32, uint32Slice []uint32) (uint32, error)

GenRandValue 生成 随机值

参数:
	except:排除 数据
	uint32Slice:从该slice中随机一个,与except不重复
返回值:
	unit32Slice 中的值

func GenRandomString

func GenRandomString(len uint32) (container string, err error)

GenRandomString 生成随机字符串

参数:
	len:需要生成的长度

func GetCurrentPath

func GetCurrentPath() (currentPath string, err error)

GetCurrentPath 获取当前程序 所在 路径

[×] 支持 win 下 link/快捷方式
[✔] 支持 linux ln -s
on linux host:ln -s /home/xxx/battle001/battle-linux.exe.001 /home/xxx/zone2/battle001/btl.exe
执行btl.exe 输出:service current path:/home/xxx/zone2/battle001

func If

func If(condition bool, trueVal interface{}, falseVal interface{}) interface{}

If 三目运算符 NOTE 传递的实参,会在调用时计算

func IsDebug

func IsDebug() bool

IsDebug 是否为调试模式

func IsDuplicateUint32

func IsDuplicateUint32(uint32Slice []uint32) bool

IsDuplicateUint32 是否有重复uint32

func IsLinux

func IsLinux() bool

IsLinux linux

func IsLittleEndian

func IsLittleEndian() bool

IsLittleEndian 判断 是小端

func IsRelease

func IsRelease() bool

IsRelease 是否为发行模式

func IsWindows

func IsWindows() bool

IsWindows win

func RandomInt

func RandomInt(min int, max int) int

RandomInt 生成范围内的随机值

参数:
	min:最小值
	max:最大值

func SplitString2Map

func SplitString2Map(s string, sep1 string, sep2 string) (map[uint32]int64, error)

SplitString2Map 拆分字符串, 返回key为uint32类型、val为int64类型的map

func SplitString2Uint32

func SplitString2Uint32(s string, sep string) (u32Slice []uint32, err error)

SplitString2Uint32 拆分字符串, 返回 uint32 类型的 slice

func WeightedRandom

func WeightedRandom(weights []uint32) (idx int, err error)

WeightedRandom 从权重中选出序号.[0 ... ]

NOTE 参数 weights 必须有长度
参数:
	weights:权重
返回值:
	idx:weights 的序号 idx

Types

type ConditionFunc

type ConditionFunc[TKey comparable, TVal IObject] func(key TKey, value TVal) bool

ConditionFunc 用于定义查找条件的函数签名

type IDisplay

type IDisplay interface {
	String() string
}

type IObject

type IObject interface {
	IDisplay
}

type Mgr

type Mgr[TKey comparable, TVal IObject] struct {
	// contains filtered or unexported fields
}

func NewMgr

func NewMgr[TKey comparable, TVal IObject]() *Mgr[TKey, TVal]

NewMgr 创建 Mgr 实例

func (*Mgr[TKey, TVal]) Add

func (p *Mgr[TKey, TVal]) Add(key TKey, value TVal)

Add 添加元素

func (*Mgr[TKey, TVal]) Del

func (p *Mgr[TKey, TVal]) Del(key TKey)

Del 删除元素

func (*Mgr[TKey, TVal]) Find

func (p *Mgr[TKey, TVal]) Find(key TKey) TVal

Find 查找元素

func (*Mgr[TKey, TVal]) FindOneWithCondition

func (p *Mgr[TKey, TVal]) FindOneWithCondition(condition ConditionFunc[TKey, TVal]) (val TVal)

FindOneWithCondition 根据条件查找元素-一个

type RunMode

type RunMode int

RunMode 运行模式

const (
	RunModeRelease RunMode = 0 //release 模式
	RunModeDebug   RunMode = 1 //debug 模式
)

Jump to

Keyboard shortcuts

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