utils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AiBaseUuid

func AiBaseUuid() string

func AppUuid

func AppUuid() string

func BToMb

func BToMb(b uint64) uint64

* * Byte to Mbyte *

func BToU16

func BToU16(b []byte, index int, offset int) uint16

func BToU32

func BToU32(b []byte, index int, offset int) uint32

func BToU64

func BToU64(b []byte, index int, offset int) uint64

func BindConfig

func BindConfig(config map[string]interface{}, s interface{}) error

Bind config to struct config: a Map, s: a struct variable

func BindSourceConfig

func BindSourceConfig(config map[string]interface{}, s interface{}) error

func BtoMB

func BtoMB(bytes uint64) float64

func CRC16

func CRC16(data []byte) uint16

func DeviceUuid

func DeviceUuid() string

func GenCode

func GenCode(fields []Field, big bool, more bool) string

func Get

func Get(client http.Client, url string) string

* * HTTP GET *

func GetINISection

func GetINISection(iniPath string, s string) *ini.Section

* * GetINI *

func GetOSDistribution added in v0.5.1

func GetOSDistribution() (string, error)

* * 获取操作系统发行版版本 runtime.GOARCH:

386: 32-bit Intel/AMD x86 architecture
amd64: 64-bit Intel/AMD x86 architecture
arm: ARM architecture (32-bit)
arm64: ARM architecture (64-bit)
ppc64: 64-bit PowerPC architecture
ppc64le: 64-bit little-endian PowerPC architecture
mips: MIPS architecture (32-bit)
mips64: MIPS architecture (64-bit)
s390x: IBM System z architecture (64-bit)
wasm: WebAssembly architecture

runtime.GOOS:

darwin: macOS
freebsd: FreeBSD
linux: Linux
windows: Windows
netbsd: NetBSD
openbsd: OpenBSD
plan9: Plan 9
dragonfly: DragonFly BSD

*

func GetPwd

func GetPwd() string

* * GetPwd *

func GiveMeMicroseconds

func GiveMeMicroseconds(c int64) time.Duration

* * 返回微秒 *

func GiveMeMilliseconds

func GiveMeMilliseconds(c int64) time.Duration

* * 返回毫秒 *

func GiveMeSeconds

func GiveMeSeconds(c int64) time.Duration

* * 返回秒 *

func GoID added in v0.5.1

func GoID() int

func GoodsUuid

func GoodsUuid() string

GoodsUuid

func GroupUuid added in v0.6.1

func GroupUuid() string

func HostNameI

func HostNameI() ([]string, error)

* * Get Local IP *

func INIToStruct

func INIToStruct(iniPath string, s string, v interface{}) error

func InIMapToStruct

func InIMapToStruct(section *ini.Section, s interface{}) error

INI转结构体

func InUuid

func InUuid() string

MakeUUID

func IsListDuplicated

func IsListDuplicated(list []string) bool

* * 检查列表元素是不是不重复了 *

func MakeUUID

func MakeUUID(prefix string) string

MakeUUID

func MaoToTerm

func MaoToTerm(input interface{}, output interface{}) error

Map转成结构体 Decode takes an input structure and uses reflection to translate it to the output structure.

output must be a pointer to a map or struct.

func NowTime added in v0.6.1

func NowTime() string

NowTime 返回当前时间串,eg: 2023-07-10 13:14:52

func NowTs added in v0.6.1

func NowTs() int64

NowTs 返回当前Unix时间戳

func OutUuid

func OutUuid() string

MakeUUID

func Paginate added in v0.6.1

func Paginate(pageNum int, pageSize int, sliceLength int) (int, int)

* * Slice分页计算器 *

func PluginUuid

func PluginUuid() string

func Post

func Post(client http.Client, data interface{},
	url string, headers map[string]string) (string, error)

* * HTTP POST *

func ReadAtLeast

func ReadAtLeast(ctx context.Context, r io.Reader, buf []byte, min int) (n int, err error)

func RuleUuid

func RuleUuid() string

MakeUUID

func SContains

func SContains(s []string, e string) bool

* * 列表包含 *

func Sleep added in v0.6.1

func Sleep(ts int)

Sleep 当前线程阻塞(休眠)指定时间,单位:毫秒

func SliceReceive

func SliceReceive(ctx context.Context,
	iio io.Reader, resultBuffer []byte,
	showError bool,
	td time.Duration) (int, error)

* * 通过一个定时时间片读取 *

func SliceReceiveAtLeast

func SliceReceiveAtLeast(ctx context.Context,
	iio io.Reader, resultBuffer []byte, td time.Duration, min int) (int, error)

* * 某个时间片期望最少收到字节数 *

func SliceReceiveWithError

func SliceReceiveWithError(ctx context.Context,
	iio io.Reader, resultBuffer []byte, td time.Duration) (int, error)

* * 读取数据的时候,如果出现错误就返回 *

func SliceReceiveWithoutError

func SliceReceiveWithoutError(ctx context.Context,
	iio io.Reader, resultBuffer []byte, td time.Duration) (int, error)

* * 读取数据的时候,如果出现错误则判断是否是串口引起的超时,如果是就忽略 *

func SliceRequest

func SliceRequest(ctx context.Context,
	iio io.ReadWriter, writeBytes []byte,
	resultBuffer []byte,
	showError bool,
	td time.Duration) (int, error)

* * 时间片读写请求 *

func TraceMemStats

func TraceMemStats()

* * DEBUG使用 *

func TransformConfig

func TransformConfig(s1 []byte, s2 interface{}) error

JSON String to a struct, (can't validate map!!!)

func TrimZero

func TrimZero(s string) string

去掉\u0000字符

func U16ToB

func U16ToB(v uint16, b []byte)

func U32ToB

func U32ToB(v uint32, b []byte)

func U64ToB

func U64ToB(v uint64, b []byte)

func VisualUuid added in v0.6.1

func VisualUuid() string

func XOR

func XOR(src []byte) int

XOR 异或运算加解密

func Zone added in v0.6.1

func Zone() string

Zone 返回当前时区

Types

type CpuUsage added in v0.5.1

type CpuUsage struct {
	Name  string `json:"name"`
	Usage uint64 `json:"usage"`
}

* * CPU *

func GetCpuUsage added in v0.5.1

func GetCpuUsage() ([]CpuUsage, error)

* * 获取CPU的使用率 *

func (CpuUsage) String added in v0.5.1

func (m CpuUsage) String() string

type DiskUsage added in v0.5.1

type DiskUsage struct {
	DeviceID  string  `json:"deviceID"`
	FreeSpace float64 `json:"freeSpace"`
	Size      float64 `json:"size"`
}

* * 磁盘 *

func GetDiskUsage added in v0.5.1

func GetDiskUsage() ([]DiskUsage, error)

* * 获取磁盘使用率 *

func (DiskUsage) String added in v0.5.1

func (m DiskUsage) String() string

type Field

type Field struct {
	Name string
	Type string
	Len  uint8
}

* * 自动生成解码器 *

type GenLuaConfig

type GenLuaConfig struct {
	Big    bool    `json:"big"`    // 大小端
	More   bool    `json:"more"`   // 需要剩下的字节?
	Fields []Field `json:"fields"` // 字段列表
}

type NetworkInterfaceUsage added in v0.5.1

type NetworkInterfaceUsage struct {
	Name                string
	CurrentBandwidth    uint64
	BytesTotalPerSec    uint64
	BytesReceivedPerSec uint64
	BytesSentPerSec     uint64
	PacketsPerSec       uint64
}

* * 网卡 *

func NetInterfaceUsage added in v0.5.1

func NetInterfaceUsage() ([]NetworkInterfaceUsage, error)

* * 获取网卡实时速率 *

func (NetworkInterfaceUsage) String added in v0.5.1

func (m NetworkInterfaceUsage) String() string

type SystemDevices added in v0.5.1

type SystemDevices struct {
	Uarts  []string `json:"uarts"`
	Videos []string `json:"videos"`
	Audios []string `json:"audios"`
}

* * 系统设备 *

func GetSystemDevices added in v0.5.1

func GetSystemDevices() (SystemDevices, error)

* * 获取设备树 *

func (SystemDevices) String added in v0.5.1

func (m SystemDevices) String() string

type Utsname added in v0.5.1

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

* * Cgo 实现, 用来获取Linux的系统参数 *

func ReleaseInfo added in v0.5.1

func ReleaseInfo() Utsname

Jump to

Keyboard shortcuts

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