utils

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AiBaseUuid

func AiBaseUuid() string

func AllowCros added in v0.6.7

func AllowCros(c *gin.Context)

* * // User Function *

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 CLog added in v0.6.5

func CLog(format string, v ...interface{})

* * 自定义日志 *

func CRC16

func CRC16(data []byte) uint16

func CatOsRelease added in v0.6.3

func CatOsRelease() (map[string]string, error)

* * Linux: cat /etc/os-release *

func CommandExists added in v0.6.4

func CommandExists(command string) bool

func CronTaskUuid added in v0.6.4

func CronTaskUuid() string

func DataSchemaUuid added in v0.6.3

func DataSchemaUuid() string

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 GetDefaultDataOrder added in v0.6.6

func GetDefaultDataOrder(Type, Order string) string

* * 默认字节序 *

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 GetUbuntuVersion added in v0.6.2

func GetUbuntuVersion() (string, error)

* * 获取Ubuntu的版本 *

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 HNC8PointUUID added in v0.6.7

func HNC8PointUUID() string

华中数控

func HandleZeroValue added in v0.6.6

func HandleZeroValue[V int16 | int32 | int64 | float32 | float64](v *V) *V

* * 处理空指针初始值 *

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 IsValidName added in v0.6.7

func IsValidName(username string) bool

* * 合法名称 *

func KDNPointUUID added in v0.6.7

func KDNPointUUID() string

凯帝恩

func MakeLongUUID added in v0.6.3

func MakeLongUUID(prefix string) string

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 ModbusPointUUID added in v0.6.5

func ModbusPointUUID() string

MakeUUID

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 ParseModbusValue added in v0.6.6

func ParseModbusValue(
	DataBlockType string,
	DataBlockOrder string,
	Weight float32,
	byteSlice [256]byte) string

* *解析 Modbus 的值 有符号, 注意:如果想解析值,必须不能超过4字节,目前常见的数一般都是4字节,也许后期会有8字节,但是目前暂时不支持 *

func ParseUSignedValue added in v0.6.6

func ParseUSignedValue(DataBlockType string, DataBlockOrder string,
	Weight float32, byteSlice [256]byte) string

* *解析西门子的值 无符号 *

func PathExists added in v0.6.5

func PathExists(path string) bool

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 PushLocalCameraToJpegStreamServer added in v0.6.7

func PushLocalCameraToJpegStreamServer(FromDevice, pushAddr string) *exec.Cmd

* * 推本地的摄像头到远程流服务器 *ffmpeg.exe -hide_banner -r 24 -rtsp_transport tcp -re -i video="USB2.0 PC CAMERA" -c:v mjpeg -f mjpeg -headers "Content-Type:multipart/x-mixed-replace" "http://127.0.0.1:9401/jpeg_stream/push?liveId=123"

func PushLocalCameraToRTMPServer added in v0.6.7

func PushLocalCameraToRTMPServer(FromDevice, pushAddr string) *exec.Cmd

* * 摄像头推流到RTMP服务器 *

func PushLocalCameraToWsServer added in v0.6.7

func PushLocalCameraToWsServer(FromDevice, pushAddr string) *exec.Cmd

* * 推送摄像头到Websocket Server ffmpeg.exe -hide_banner -r 24 -rtsp_transport tcp -re -i device=/dev/video0 -c:v mjpeg -f mjpeg -headers "Content-Type:multipart/x-mixed-replace" "http://127.0.0.1:9401/jpeg_stream/push?liveId=123"

func PushRtspToJpegStreamServer added in v0.6.7

func PushRtspToJpegStreamServer(From, ToUrl string) *exec.Cmd

* * 推送Rtsp流 ffmpeg.exe -hide_banner -r 24 -rtsp_transport tcp -re -i rtsp://192.168.1.210:554/av0_0 -c:v mjpeg -f mjpeg -headers "Content-Type:multipart/x-mixed-replace" "http://127.0.0.1:9401/jpeg_stream/push?liveId=123"

func PushRtspToRTMPServer added in v0.6.7

func PushRtspToRTMPServer(inputUrl, pushAddr string) *exec.Cmd

* * Push to rtmp ffmpeg.exe -hide_banner -rtsp_transport tcp -re -i rtsp://192.168.1.210:554/av0_0 -q 5 -f flv rtmp://127.0.0.1:1935

func PushRtspToWsServer added in v0.6.7

func PushRtspToWsServer(inputUrl, pushAddr string) *exec.Cmd

* * 推送RTSP到Websocket Server ffmpeg.exe -hide_banner -r 24 -rtsp_transport tcp -re -i rtsp://192.168.1.210:554/av0_0 -i .\meteorology.png -filter_complex "[0:v][1:v]overlay=10:10:alpha=0.5" -q 5 -f mpegts -fflags nobuffer -c:v libx264 -an http://127.0.0.1:9400/h264_stream/push?liveId=123

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 ShowGGpuAndCpuInfo added in v0.6.7

func ShowGGpuAndCpuInfo()

* * 展示硬件信息 *

func SiemensPointUUID added in v0.6.5

func SiemensPointUUID() string

MakeUUID

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 UserLuaUuid added in v0.6.5

func UserLuaUuid() string

MakeUUID

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 AddressInfo added in v0.6.6

type AddressInfo struct {
	AddressType     string // 寄存器类型: DB I Q
	DataBlockType   string // 数据类型: BYTE SHORT INT
	DataBlockSize   int    // 数据长度
	DataBlockOrder  string // 字节序
	DataBlockNumber int    // 数据块号
	ElementNumber   int    // 元素号
	BitNumber       int    // 位号,只针对I、Q
}

AddressInfo 包含解析后的地址信息

func ParseSiemensDB added in v0.6.6

func ParseSiemensDB(s string) (AddressInfo, error)

* * 解析地址 *

func (AddressInfo) String added in v0.6.6

func (O AddressInfo) String() string

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 Resolution added in v0.6.7

type Resolution struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

* * Jpeg Stream 帧 *

func CvMatToImageBytes added in v0.6.7

func CvMatToImageBytes(FrameBuffer []byte) ([]byte, Resolution, error)

func GetVideoResolution added in v0.6.7

func GetVideoResolution(FrameBuffer []byte) Resolution

func (Resolution) String added in v0.6.7

func (O Resolution) 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