utils

package
v0.0.0-...-0aeb70d Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: AGPL-3.0 Imports: 66 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func BytesFromat

func BytesFromat(raw uint64) float64

字节(GB)单位转换: bit(位)、Byte(字节)、KB(千字节)、MB(兆字节)、GB(吉字节,千兆)、TB(万亿字节,太字节)、PB(千万亿字节,拍字节)、EB(百亿亿字节,艾字节)、ZB(十万亿亿字节,泽字节)、YB(一亿亿亿字节,尧字节)、BB(千亿亿亿字节) 1BB=1024YB=1024^2ZB=1024^3EB=1024^4PB=1024^5TB=1024^6GB=1024^7MB=1024^8KB=1024^9Byte=8*1024^9bit 1YB=1024ZB=1024^2EB=1024^3PB=1024^4TB=1024^5GB=1024^6MB=1024^7KB=1024^8Byte=8*1024^8bit 1ZB=1024EB=1024^2PB=1024^3TB=1024^4GB=1024^5MB=1024^6KB=1024^7Byte=8*1024^7bit 1EB=1024PB=1024^2TB=1024^3GB=1024^4MB=1024^5KB=1024^6Byte=8*1024^6bit 1PB=1024TB=1024^2GB=1024^3MB=1024^4KB=1024^5Byte=8*1024^5bit 1TB=1024GB=1024^2MB=1024^3KB=1024^4Byte=8*1024^4bit 1GB=1024MB=1024^2KB=1024^3Byte=8*1024^3bit 1MB=1024KB=1024^2Byte=8*1024^2bit 1KB=1024Byte=8*1024bit 1Byte=8bit

func Compress

func Compress(data []byte, algorithm string) ([]byte, error)

压缩

func CompressWithFlate

func CompressWithFlate(data []byte) ([]byte, error)

flate 压缩

func CompressWithGzip

func CompressWithGzip(data []byte) ([]byte, error)

gzip 压缩

func CompressWithLzw

func CompressWithLzw(data []byte) ([]byte, error)

Lempel-Ziv-Welch (LZW) 压缩

func CompressWithZlib

func CompressWithZlib(data []byte) ([]byte, error)

zlib 压缩

func CreateDirIFNotExist

func CreateDirIFNotExist(dir string) error

如果目录不存在就创建目录

func CreateFileIFNotExist

func CreateFileIFNotExist(file string) error

如果文件不存在就创建文件及文件所在目录

func Decimal

func Decimal(value float64, precision int) float64

保留小数位数: precision: 精度/小数位数

func Decrypt

func Decrypt(secret []byte, raw []byte) ([]byte, error)

func Encrypt

func Encrypt(secret []byte, raw []byte) ([]byte, error)

func FileAbsolutePath

func FileAbsolutePath(file string) (string, error)

获取文件/目录的绝对路径

func FileIsExist

func FileIsExist(file string) (path string, err error)

判断文件/目录是否存在

func FileIsZip

func FileIsZip(file string) (bool, error)

判断文件是否是压缩/归档文件

func FileWalk

func FileWalk(dir string) (dirs []string, files []string, err error)

遍历目录

func FilesAndDirs

func FilesAndDirs(dir string) (dirs []string, files []string, err error)

获取文件和目录列表

func FrequencyFormat

func FrequencyFormat(raw float64) float64

主频(GHz)单位转换: Hz、KHz、MHz、GHz、THz 1THz=10^3GHz=10^6MHz=10^9KHz=10^12Hz 1GHz=10^3MHz=10^6KHZ=10^9Hz 1MHz=10^3KHz=10^6Hz 1KHz=10^3Hz

func GetIPv4Address

func GetIPv4Address() (ips []string)

IPv4 地址列表

func GetIPv6Address

func GetIPv6Address() (ips []string)

IPv6 地址列表

func GetMacAddress

func GetMacAddress() (macs []string)

MAC 地址列表

func GetNode

func GetNode() (ips []string)

节点信息[节点IP(ipv4,ipv6)列表]

func GobDecode

func GobDecode(raw []byte, object any, algorithm string) error

gob 格式反序列化

raw []byte : 序列化数据 object any : 反序列化接收对象 algorithm string : 解压缩算法

func GobEncode

func GobEncode(object any, compress bool, algorithm string) ([]byte, error)

gob 格式序列化

object any : 序列化对象 compress bool : 是否进行压缩 algorithm string : 压缩算法

func Int64SliceSegments

func Int64SliceSegments(raw []int64, number int64) [][]int64

int64切片分片 raw: 原字符串切片 number: 分片元素大小

func IsError

func IsError(err error) bool

判断错误是否为自定义错误

func JsonDecode

func JsonDecode(raw []byte, object any, algorithm string) error

json 格式反序列化

raw []byte : 序列化数据 object any : 反序列��接收对象 algorithm string : 解压缩算法

func JsonEncode

func JsonEncode(object any, escape bool, compress bool, algorithm string) ([]byte, error)

json 格式序列化

object any : 序列化对象 escape bool : 是否进行转义 compress bool : 是否进行压缩 algorithm string : 压缩算法

func MillisecondTimestampFormatDaysHoursMinutesSeconds

func MillisecondTimestampFormatDaysHoursMinutesSeconds(timestamp float64) (days int32, hours int32, minutes int32, seconds float64)

毫秒时间戳格式化

func Number2Float32

func Number2Float32(value any, precision float32) float32

数值类型转换成float32类型,precision: 精度/倍乘数/倍乘因子

func Number2Float64

func Number2Float64(value any, precision float64) float64

数值类型转换成float64类型,precision: 精度/倍乘数/倍乘因子

func Number2Int16

func Number2Int16(value any, precision int16) int16

数值类型转换成int16类型,precision: 精度/倍乘数/倍乘因子

func Number2Int32

func Number2Int32(value any, precision int32) int32

数值类型转换成int32类型,precision: 精度/倍乘数/倍乘因子

func Number2Int64

func Number2Int64(value any, precision int64) int64

数值类型转换成int64类型,precision: 精度/倍乘数/倍乘因子

func Number2Int8

func Number2Int8(value any, precision int8) int8

数值类型转换成int8类型,precision: 精度/倍乘数/倍乘因子

func Number2Uint16

func Number2Uint16(value any, precision uint16) uint16

数值类型转换成uint16类型,precision: 精度/倍乘数/倍乘因子

func Number2Uint32

func Number2Uint32(value any, precision uint32) uint32

数值类型转换成uint32类型,precision: 精度/倍乘数/倍乘因子

func Number2Uint64

func Number2Uint64(value any, precision uint64) uint64

数值类型转换成uint64类型,precision: 精度/倍乘数/倍乘因子

func Number2Uint8

func Number2Uint8(value any, precision uint8) uint8

数值类型转换成uint8类型,precision: 精度/倍乘数/倍乘因子

func OuiQuery

func OuiQuery(mac string) (entry *oui.Entry, err error)

func ParseAddress

func ParseAddress(address string) (schema string, host string, ips []net.IP, port int, err error)

func StringSliceSegments

func StringSliceSegments(raw []string, number int) [][]string

字符串切片分片 raw: 原字符串切片 number: 分片元素大小

func TomlDecode

func TomlDecode(raw []byte, object any, algorithm string) error

toml 格式反序列化

raw []byte : 序列化数据 object any : 反序列化接收对象 algorithm string : 解压缩算法

func TomlEncode

func TomlEncode(object any, compress bool, algorithm string) ([]byte, error)

toml 格式序列化

object any : 序列化对象 compress bool : 是否进行压缩 algorithm string : 压缩算法

func TrafficbpsFormatKMGTPEZYBbps

func TrafficbpsFormatKMGTPEZYBbps(trafficbps float64) (result float64, unit string)

流量单位转换: bps(位/秒)、Kbps(千字节/秒)、Mbps(兆字节/秒)、Gbps(吉字节/秒,千兆/秒)、Tbps(万亿字节/秒,太字节/秒)、Pbps(千万亿字节/秒,拍字节/秒)、Ebps(百亿亿字节/秒,艾字节/秒)、Zbps(十万亿亿字节/秒,泽字节/秒)、Ybps(一亿亿亿字节/秒,尧字节/秒)、Bbps(千亿亿亿字节/秒) 1bps=1bps 1Kbps=1024bps 1Mbps=1024Kbps=1024^2=1024^2bps 1Gbps=1024Mbps=1024^2Kbps=1024^3bps=1024^3bps 1Tbps=1024Gbps=1024^2Mbps=1024^3Kbps=1024^4bps 1Pbps=1024Tbps=1024^2Gbps=1024^3Mbps=1024^4Kbps=1024^5bps 1Ebps=1024Pbps=1024^2Tbps=1024^3Gbps=1024^4Mbps=1024^5Kbps=1024^6bps 1Zbps=1024Ebps=1024^2Pbps=1024^3Tbps=1024^4Gbps=1024^5Mbps=1024^6Kbps=1024^7bps 1Ybps=1024Zbps=1024^2Ebps=1024^3Pbps=1024^4Tbps=1024^5Gbps=1024^6Mbps=1024^7Kbps=1024^8bps 1Bbps=1024Ybps=1024^2Zbps=1024^3Ebps=1024^4Pbps=1024^5Tbps=1024^6Gbps=1024^7Mbps=1024^8Kbps=1024^9bps

func TrimAllSpace

func TrimAllSpace(raw string) string

去除所有空格

func TrimAllSymbol

func TrimAllSymbol(raw string, symbol string) string

去除所有指定符号

func TrimBeforeAndAfterBackslash

func TrimBeforeAndAfterBackslash(raw string) string

去除前后指定\号

func TrimBeforeAndAfterPoint

func TrimBeforeAndAfterPoint(raw string) string

去除前后指定.号

func TrimBeforeAndAfterSlash

func TrimBeforeAndAfterSlash(raw string) string

去除前后指定/号

func TrimBeforeAndAfterSpace

func TrimBeforeAndAfterSpace(raw string) string

去除前后所有空格

func TrimBeforeAndAfterSymbol

func TrimBeforeAndAfterSymbol(raw string, symbol string) string

去除前后指定符号

func Uint64SliceSegments

func Uint64SliceSegments(raw []uint64, number int64) [][]uint64

uint64切片分片 raw: 原字符串切片 number: 分片元素大小

func UnCompress

func UnCompress(data []byte, algorithm string) ([]byte, error)

解压

func UnCompressWithFlate

func UnCompressWithFlate(raw []byte) ([]byte, error)

flate 解压

func UnCompressWithGzip

func UnCompressWithGzip(raw []byte) ([]byte, error)

gzip 解压

func UnCompressWithLzw

func UnCompressWithLzw(raw []byte) ([]byte, error)

Lempel-Ziv-Welch (LZW) 解压

func UnCompressWithZlib

func UnCompressWithZlib(raw []byte) ([]byte, error)

zlib 解压

func UnitFormat

func UnitFormat(size uint64) string

字节的单位转换,保留两位小数

func ValidateNil

func ValidateNil(object any) bool

func ValidateStruct

func ValidateStruct(object any, language string) error

func XmlDecode

func XmlDecode(raw []byte, object any, algorithm string) error

xml 格式反序列化

raw []byte : 序列化数据 object any : 反序列化接收对象 algorithm string : 解压缩算法

func XmlEncode

func XmlEncode(object any, namespace string, root string, compress bool, algorithm string) ([]byte, error)

xml 格式序列化

object any : 序列化对象 namespace string : 命名空间 root string : 根节点名称 compress bool : 是否进行压缩 algorithm string : 压缩算法

func YamlDecode

func YamlDecode(raw []byte, object any, algorithm string) error

yaml 格式反序列化

raw []byte : 序列化数据 object any : 反序列化接收对象 algorithm string : 解压缩算法

func YamlEncode

func YamlEncode(object any, compress bool, algorithm string) ([]byte, error)

yaml 格式序列化

object any : 序列化对象 compress bool : 是否进行压缩 algorithm string : 压缩算法

Types

type Error

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

自定义错误类型

func NewError

func NewError(code int32, reason string) Error

func (Error) Error

func (e Error) Error() string

func (Error) GetCode

func (e Error) GetCode() int32