utils

package
v0.0.0-...-ef65237 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: AGPL-3.0 Imports: 69 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IPv4Regexp = regexp.MustCompile(ipv4RegexParten)

	IPv6Regexp = regexp.MustCompile(ipv6RegexParten)
)
View Source
var (
	// 匹配空格
	RegexpSpace = regexp.MustCompile(`\s`)
	// 匹配以空格开头
	RegexpPrefixSpace = regexp.MustCompile(`^\s`)
	// 匹配以空格结尾
	RegexpSuffixSpace = regexp.MustCompile(`\s$`)
	// 匹配以空格开头或结尾
	RegexpPrefixAndSuffixSpace = regexp.MustCompile(`^\s|\s$`)
	// 匹配以[.]开头
	RegexpPrefixPoint = regexp.MustCompile(`^\.`)
	// 匹配以[.]结尾
	RegexpSuffixPoint = regexp.MustCompile(`\.$`)
	// 匹配以[.]开头或结尾
	RegexpPrefixAndSuffixPoint = regexp.MustCompile(`^\.|\\.$`)
	// 匹配以[/]开头
	RegexpPrefixSlash = regexp.MustCompile(`^\/`)
	// 匹配以[/]结尾
	RegexpSuffixSlash = regexp.MustCompile(`\/$`)
	// 匹配以[/]开头或结尾
	RegexpPrefixAndSuffixSlash = regexp.MustCompile(`^\/|\/$`)
	// 匹配以[\]开头
	RegexpPrefixBackSlash = regexp.MustCompile(`^\\`)
	// 匹配以[\]结尾
	RegexpSuffixBackSlash = regexp.MustCompile(`\\$`)
	// 匹配以[\]开头或结尾
	RegexpPrefixAndSuffixBackSlash = regexp.MustCompile(`^\\|\\$`)

	// 匹配以[`]开头
	RegexpPrefixBackTick = regexp.MustCompile(`^` + "`")
	// 匹配以[`]结尾
	RegexpSuffixBackTick = regexp.MustCompile("`$")
	// 匹配以[`]开头或结尾
	RegexpPrefixAndSuffixBackTick = regexp.MustCompile(`^` + "`" + `|` + "`" + `$`)

	// 匹配以[*]开头
	RegexpPrefixAsterisk = regexp.MustCompile(`^\*`)
	// 匹配以[*]结尾
	RegexpSuffixAsterisk = regexp.MustCompile(`\*$`)
	// 匹配以[*]开头或结尾
	RegexpPrefixAndSuffixAsterisk = regexp.MustCompile(`(^\*|\*$)`)

	// 匹配协议
	RegexpSchema = regexp.MustCompile(`(?i)^(http|https|rpc|grpc|ws|wss|snmp|sip)\:\/\/`)

	// 匹配字母、数字的正则表达���
	LetterDigitRegexp = regexp.MustCompile(`^[a-zA-Z0-9]+$`)
	// 匹配非字母、数字的正则表达式
	NonLetterDigitRegexp = regexp.MustCompile(`[^a-zA-Z0-9]`)
)
View Source
var (
	// 常见端口
	CommonPorts = []uint{80, 8080, 5000, 443, 554, 8554, 22, 5060, 3389}
)

时间格式集合

Functions

func AutoParseTimeFromString

func AutoParseTimeFromString(raw string) (result time.Time, layout string, err error)

自动解析时间格式

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 CheckWritePermission

func CheckWritePermission(dir string) error

CheckWritePermission 检查指定目录是否具有写入权限

func ComparePaths

func ComparePaths(path1, path2 string) (bool, error)

ComparePaths 比较两个路径是否相等,兼容不同操作系统

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) (err error)

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

func CreateFileIFNotExist

func CreateFileIFNotExist(file string) (absolute string, err error)

如果文件不存在就创建文件及文件所在目录,并返回文件绝对路径

func DSNIsMemory

func DSNIsMemory(dsn string) bool

*

  • @description: 判断 数据来源名称(Data Source Name) 是否是内存
  • @param [string] dsn 数据来源名称(Data Source Name)
  • @return [bool] 布尔值

func Decimal

func Decimal(value float64, precision int) float64

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

func DistinctStringSlice2String

func DistinctStringSlice2String(raw []string, symbol string) string

字符串切片去重,返回指定分隔符字符串

func DistinctStringSlice2StringSlice

func DistinctStringSlice2StringSlice(raw []string) []string

字符串切片去重,返回字符串切片

func ExecuteCommand

func ExecuteCommand(command string, args string) (table map[string]string, err error)

通用命令执行和解析

func FileIsExist

func FileIsExist(file string) (path 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 GetARPTable

func GetARPTable() (table map[string]string, err error)

GetARPTable 获取 ARP 表

func GetAllIPsInSubnetExceptSelf

func GetAllIPsInSubnetExceptSelf(ipNet *net.IPNet) ([]net.IP, error)

GetAllIPsInSubnetExceptSelf 获取子网内除自身外的所有 IP 地址

func GetCurrentMonth

func GetCurrentMonth() int32

*

  • @description: 获取当前月份

func GetCurrentMonthDay

func GetCurrentMonthDay() int32

*

  • @description: 获取当月第几天

func GetCurrentMonthWeek

func GetCurrentMonthWeek() int32

*

  • @description: 获取当月第几个星期

func GetCurrentMonthWorkDay

func GetCurrentMonthWorkDay() int32

*

  • @description: 获取当前日期是当月第几个工作日

func GetCurrentQuarter

func GetCurrentQuarter() int32

*

  • @description: 获取当前季度

func GetCurrentQuarterDay

func GetCurrentQuarterDay() int32

*

  • @description: 获取当前季度第几天

func GetCurrentQuarterWeek

func GetCurrentQuarterWeek() int32

*

  • @description: 获取当前季度第几个星期

func GetCurrentTime

func GetCurrentTime() time.Time

*

  • @description: 获取当前时间

func GetCurrentTimezoneAndOffset

func GetCurrentTimezoneAndOffset() (string, int32)

*

  • @description: 获取当前时区以及当前时区与UTC时区相距的秒数

func GetCurrentUTCMonth

func GetCurrentUTCMonth() int32

*

  • @description: 获取当前 UTC 月份

func GetCurrentUTCMonthDay

func GetCurrentUTCMonthDay() int32

*

  • @description: 获取 UTC 当月第几天

func GetCurrentUTCMonthWeek

func GetCurrentUTCMonthWeek() int32

*

  • @description: 获取 UTC 当月第几个星期

func GetCurrentUTCMonthWorkDay

func GetCurrentUTCMonthWorkDay() int32

*

  • @description: 获取 UTC 当前日期是当月第几个工作日

func GetCurrentUTCQuarter

func GetCurrentUTCQuarter() int32

*

  • @description: 获取当前 UTC 季度

func GetCurrentUTCQuarterDay

func GetCurrentUTCQuarterDay() int32

*

  • @description: 获取 UTC 当前季度第几天

func GetCurrentUTCQuarterWeek

func GetCurrentUTCQuarterWeek() int32

*

  • @description: 获取 UTC 当前季度第几个星期

func GetCurrentUTCTime

func GetCurrentUTCTime() time.Time

*

  • @description: 获取当前 UTC 时间

func GetCurrentUTCWeekDay

func GetCurrentUTCWeekDay() int32

*

  • @description: 获取 UTC 当前星期第几天

func GetCurrentUTCYear

func GetCurrentUTCYear() int32

*

  • @description: 获取当前 UTC 年份

func GetCurrentUTCYearDay

func GetCurrentUTCYearDay() int32

*

  • @description: 获取 UTC 当年第几天

func GetCurrentUTCYearWeek

func GetCurrentUTCYearWeek() int32

*

  • @description: 获取 UTC 当年第几个星期

func GetCurrentUTCYearWorkDay

func GetCurrentUTCYearWorkDay() int32

*

  • @description: 获取 UTC 当前日期是当年第几个工作日

func GetCurrentWeekDay

func GetCurrentWeekDay() int32

*

  • @description: 获取当前星期第几天

func GetCurrentYear

func GetCurrentYear() int32

*

  • @description: 获取当前年份

func GetCurrentYearDay

func GetCurrentYearDay() int32

*

  • @description: 获取当年第几天

func GetCurrentYearWeek

func GetCurrentYearWeek() int32

*

  • @description: 获取当年第几个星期

func GetCurrentYearWorkDay

func GetCurrentYearWorkDay() int32

*

  • @description: 获取当前日期是当年第几个工作日

func GetFileAbsolutePath

func GetFileAbsolutePath(file string) (string, error)

*

  • @description: 获取文件/目录的绝对路径
  • @param [string] file 源文件
  • @return [string] 文件/目录的绝对路径
  • @return [error] 错误信息

func GetFileRelativePath

func GetFileRelativePath(file string) (string, error)

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

func GetFileRelativeWithoutParentFlagPath

func GetFileRelativeWithoutParentFlagPath(file string) (string, error)

获取文件的相对无上级标记(../)路径

func GetFileTypeByContent

func GetFileTypeByContent(filename string) (string, error)

根据文件内容获取文件类型

func GetFileTypeBySuffix

func GetFileTypeBySuffix(filename string) (string, error)

根据文件后缀获取���件类型

func GetIPv4Address

func GetIPv4Address() (ips []string)

IPv4 地址列表

func GetIPv6Address

func GetIPv6Address() (ips []string)

IPv6 地址列表

func GetIneterfaces

func GetIneterfaces() ([]net.Interface, error)

GetIneterfaces 获取所有的网卡

func GetInterfaceByIP

func GetInterfaceByIP(ip net.IP) *net.Interface

GetInterfaceByIP 根据 局域网 IP 获取对应的网卡

func GetInterfaceIPs

func GetInterfaceIPs(iface *net.Interface, protocol string) ([]net.IP, error)

获取接口的指定协议地址列表

func GetLANIPByDNS

func GetLANIPByDNS(address string, timeout time.Duration) net.IP

GetLANIPByDNS 通过发送 DNS 服务请求获取 局域网(LAN) IP 利用 net.DialUDP 函数建立一个 UDP 连接到 8.8.8.8 的 53 端口(DNS 服务端口)

func GetLANIPs

func GetLANIPs() []net.IP

GetLANIPs 获取 局域网(LAN) IP 列表

func GetLinuxARPTable

func GetLinuxARPTable() (table map[string]string, err error)

GetLinuxARPTable Linux 处理逻辑

func GetMACFromIP

func GetMACFromIP(ip string) (string, error)

GetMACFromIP 根据 IP 地址从系统 ARP 缓存中获取 MAC 地址(带验证)

func GetMacAddress

func GetMacAddress() (macs []string)

MAC 地址列表

func GetMacByIP

func GetMacByIP(ip string) (string, error)

GetMacByIP 根据 IP 地址从系统 ARP 缓存中获取 MAC 地址(带验证)

func GetMacOSARPTable

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

GetMacOSARPTable macOS 处理逻辑

func GetNode

func GetNode() (ips []string)

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

func GetNowTime

func GetNowTime() (now time.Time,
	year int32,
	month int32,
	day int32,
	secondTimestamp int64,
	millisecondTimestamp int64,
	nanosecondTimestamp int64)

*

  • @description: 获取当前时间相关信息
  • 当前时间(currentTime)
  • 当前年份(year)
  • 当前月��(month)
  • 当前季度(quarter)
  • 当前星期(week)
  • 当前年份的第几周(yearWeek)
  • 当前月的第几周(monthWeek)
  • 当前季度的第几周(quarterWeek)
  • 当前年份的第几天(yearDay)
  • 当前月的第几天(monthDay)
  • 当前季度的第几天(quarterDay)
  • 当前星期的第几天(weekDay)
  • 当前小时(Hour)
  • 当前季度的小时(QuarterHour)
  • 当前星期的小时(WeekHour)
  • 当前日的小时(DayHour)
  • 当前时间戳(秒、毫秒、纳秒)(SecondsTimestamp, MillisecondsTimestamp, NanosecondsTimestamp

func GetStartNanoTimestamp

func GetStartNanoTimestamp(start int) int64

获取某一天开始的纳秒时间戳

func GetTimestampTime

func GetTimestampTime(timestamp int64) time.Time

根据时间戳获取时间

func GetUpAndBroadcastAndMulticastAndRunningInterfaces

func GetUpAndBroadcastAndMulticastAndRunningInterfaces() ([]net.Interface, error)

GetUpAndBroadcastAndMulticastAndRunningInterfaces 获取所有启用(up),广播(broadcast),组播(multicast),正常运行(running)的网卡

func GetUpAndPointtopointAndMulticastAndRunningInterfaces

func GetUpAndPointtopointAndMulticastAndRunningInterfaces() ([]net.Interface, error)

GetUpAndPointtopointAndMulticastAndRunningInterfaces 获取所有启用(up),点对点(pointtopoint),组播(multicast),正常运行(running)的网卡

func GetUpAndRunningInterfaces

func GetUpAndRunningInterfaces() ([]net.Interface, error)

GetUpAndRunningInterfaces 获取所有启用(up),正常运行(running)的网卡 net.FlagUp: 0 :表明网卡处于启用状态,要是这个标志被设置,就意味着网卡已经开启并且可以正常工作 net.FlagBroadcast: 1 :表示网卡支持广播功能,支持广播的网卡能够向网络中的所有设备发送数据包 net.FlagLoopback: 2 :意味着网卡是��环接口,回环接口主要用于本地测试,数据包不会被发送到物理网络,而是直接返回给本地系统 net.FlagPointToPoint: 3 :表示网卡是点对点接口,这种接口通常用于连接两个特定的设备,像 PPP 连接 net.FlagMulticast: 4 :表示网卡支持组播功能,支持组播的网卡能够向网络中的一组特定设备发送数据包 net.FlagRunning: 5 :这个标志表示网络接口处于运行状态,与 FlagUp 不同,FlagUp 侧重于管理层面的启用,而 FlagRunning 更强调网络接口在物理层面或者实际操作中正在正常工作

func GetWindowsARPTable

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

GetWindowsARPTable Windows 处理逻辑

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 IPToUint

func IPToUint(ip net.IP) uint32

IPToUint 将 IP 地址转换为 uint32

func IsGoFile

func IsGoFile(filename string) bool

IsGoFile 判断输入的文件名是否以 .go 结尾

func IsIPInRange

func IsIPInRange(ip, network, broadcast net.IP) bool

IsIPInRange 检查 IP 是否在网络范围内

func IsLANIP

func IsLANIP(ip net.IP) bool

IsLANIP 判断是否为 局域网(LAN) IP

func IsLoopbackIP

func IsLoopbackIP(ip net.IP) bool

IsLoopbackIP 判断是否为 本地回环 IP

func IsPublicHoliday

func IsPublicHoliday(t time.Time) bool

判断某一天是否是中国的法定节假日

func IsURLEncoded

func IsURLEncoded(s string) bool

IsURLEncoded 检查字符串是否可能经过URL编码

func IsURLEncodedByDecoding

func IsURLEncodedByDecoding(s string) bool

IsURLEncodedByDecoding 尝试解码并检查结果

func IsValidMAC

func IsValidMAC(mac string) (string, bool)

IsValidMAC 检查 MAC 地址 是否有效 支持的格式: - 00:1A:2B:3C:4D:5E (冒号分隔) - 00-1A-2B-3C-4D-5E (连字符分隔) - 001A2B3C4D5E (无分隔符)

func IsValidStandMAC

func IsValidStandMAC(mac string) (string, bool)

IsValidStandMAC 是否是标准有效的 MAC 校验

func IsWANIP

func IsWANIP(ip net.IP) bool

IsWANIP 判断是否为 互联网(WAN) IP

func IsWeekday

func IsWeekday(t time.Time) bool

判断某一天是否是工作��(周一到周五为工作日)

func IsWeekend

func IsWeekend(t time.Time) bool

判断某一天是否为周末(周六或周日)

func IsWorkday

func IsWorkday(t time.Time) 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 MDNSSearch

func MDNSSearch(pctx context.Context, serviceType string, timeout time.Duration) (err error)

func MicrosecondsStatistics

func MicrosecondsStatistics(number int64) (years int32, months int32, days int32, hours int32, minutes int32, seconds int32, milliseconds int32, microseconds int32, nanoseconds int32)

微秒时长统计(统计经历时长/总计时长): 多少年,多少月,多少天,多少小时,多少分钟,多少秒,多少毫秒,多少微秒,多少纳秒

func MillisecondTimestampFormatDaysHoursMinutesSeconds

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

毫秒时间戳格式化

func MillisecondsStatistics

func MillisecondsStatistics(number int64) (years int32, months int32, days int32, hours int32, minutes int32, seconds int32, milliseconds int32, microseconds int32, nanoseconds int32)

毫秒时长统计(统计经历时长/总计时长): 多少年,多少月,多少天,多少小时,多少分钟,多少秒,多少毫秒,多少微秒,多少纳秒

func NanosecondsStatistics

func NanosecondsStatistics(number int64) (years int32, months int32, days int32, hours int32, minutes int32, seconds int32, milliseconds int32, microseconds int32, nanoseconds int32)

纳秒时长统计(统计经历时长/总计时长): 多少年,多少月,多少天,多少小时,多少分钟,多少秒,多少毫秒,多少微秒,多少纳秒

func NormalizeMAC

func NormalizeMAC(mac string) (string, bool)

NormalizeMAC 将 MAC 地址标准化为冒号分隔格式 如 001A2B3C4D5E 转为 00:1A:2B:3C:4D:5E

func NormalizePath

func NormalizePath(p string) (string, error)

NormalizePath 规范化文件路径,适应不同操作系统的分隔符和大小写问题

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 ParseARPCommandOutput

func ParseARPCommandOutput(output string) (table map[string]string)

解析 arp 命令输出

func ParseAddress

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

func ParseProcNetARP

func ParseProcNetARP() (table map[string]string, err error)

解析/proc/net/arp文件

func ParseURLEncodedByDecoding

func ParseURLEncodedByDecoding(raw string) string

ParseURLEncodedByDecoding 尝试解码

func RandomString

func RandomString(length int) string

RandomString 函数生成指定长度的随机字符串 length 是要生成的字符串的长度 返回生成的随机字符串

func RegexpTrimAllPrefixAndSuffixAsterisk

func RegexpTrimAllPrefixAndSuffixAsterisk(raw string) string

正则去除字符串所有[*]前缀和[*]后缀

func RegexpTrimAllPrefixAndSuffixBackSlash

func RegexpTrimAllPrefixAndSuffixBackSlash(raw string) string

正则去除字���串所有[\]前缀和[\]后缀

func RegexpTrimAllPrefixAndSuffixBackTick

func RegexpTrimAllPrefixAndSuffixBackTick(raw string) string

正则去除字符串所有[`]前缀和[`]后缀

func RegexpTrimAllPrefixAndSuffixPoint

func RegexpTrimAllPrefixAndSuffixPoint(raw string) string

正则去除字符串所有[.]前缀和[.]后缀

func RegexpTrimAllPrefixAndSuffixSlash

func RegexpTrimAllPrefixAndSuffixSlash(raw string) string

正则去除字符串所有[/]前缀和[/]后缀

func RegexpTrimAllPrefixAndSuffixSpace

func RegexpTrimAllPrefixAndSuffixSpace(raw string) string

正则去除字符串所有空格前缀和空格后缀

func RegexpTrimAllPrefixAndSuffixSymbol

func RegexpTrimAllPrefixAndSuffixSymbol(raw string, symbol string) string

正则指定去除字符串所有前缀和后缀

func RegexpTrimAllPrefixAsterisk

func RegexpTrimAllPrefixAsterisk(raw string) string

正则去除字符串所有[*]前缀

func RegexpTrimAllPrefixBackSlash

func RegexpTrimAllPrefixBackSlash(raw string) string

正则去除字符串所有[\]前缀

func RegexpTrimAllPrefixBackTick

func RegexpTrimAllPrefixBackTick(raw string) string

正则去除字符串所有[`]前缀

func RegexpTrimAllPrefixPoint

func RegexpTrimAllPrefixPoint(raw string) string

正则去除字符串所有[.]前缀

func RegexpTrimAllPrefixSlash

func RegexpTrimAllPrefixSlash(raw string) string

正则去除字符串所有[/]前缀

func RegexpTrimAllPrefixSpace

func RegexpTrimAllPrefixSpace(raw string) string

正则去除字符串所有空格前缀

func RegexpTrimAllPrefixSymbol

func RegexpTrimAllPrefixSymbol(raw string, symbol string) string

正则指定去除字符串所有前缀

func RegexpTrimAllSpace

func RegexpTrimAllSpace(raw string) string

正则去除字符串所有空格

func RegexpTrimAllSuffixAsterisk

func RegexpTrimAllSuffixAsterisk(raw string) string

正则去除字符串所有[*]后缀

func RegexpTrimAllSuffixBackSlash

func RegexpTrimAllSuffixBackSlash(raw string) string

正��去除字符串所有[\]后缀

func RegexpTrimAllSuffixBackTick

func RegexpTrimAllSuffixBackTick(raw string) string

正则去除字符串所有[`]后缀

func RegexpTrimAllSuffixPoint

func RegexpTrimAllSuffixPoint(raw string) string

正则去除字符串所有[.]后缀

func RegexpTrimAllSuffixSlash

func RegexpTrimAllSuffixSlash(raw string) string

正则去除字符串所有[/]后缀

func RegexpTrimAllSuffixSpace

func RegexpTrimAllSuffixSpace(raw string) string

正则去除字符串所有空格后缀

func RegexpTrimAllSuffixSymbol

func RegexpTrimAllSuffixSymbol(raw string, symbol string) string

正则指定去除字符串所有后缀

func RemoveStringSliceElement

func RemoveStringSliceElement(raw []string, elements ...string) []string

去除字符串切片中的元素

func SecondsStatistics

func SecondsStatistics(number int64) (years int32, months int32, days int32, hours int32, minutes int32, seconds int32, milliseconds int32, microseconds int32, nanoseconds int32)

秒时长统计(统计经历时长/总计时长): 多少年,多少月,多少天,多少小时,多少分钟,多少秒,多少毫秒,多少微秒,多少纳秒

func TimestampFormat

func TimestampFormat(timestamp int64, layout string) string

���间戳格式化

func TimestampParse

func TimestampParse(timestamp int64) (year int, month int, day int, hour int, minute int, second int, millisecond int, microsecond int, nanosecond int)

时间戳解析: 年,月,日,时,分,秒,毫秒,微妙,纳秒

func ToCamelCase

func ToCamelCase(input string) string

ToCamelCase 首字母小写

func ToSnakeCase

func ToSnakeCase(raw string) string

将给定字符串转换为下划线分隔的小写字母形式

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 TrimAllPrefixAndSuffixAsterisk

func TrimAllPrefixAndSuffixAsterisk(raw string) string

去除字符串所有[*]前缀和[*]后缀

func TrimAllPrefixAndSuffixBackSlash

func TrimAllPrefixAndSuffixBackSlash(raw string) string

去除字符串所有[\]前缀和[\]后缀

func TrimAllPrefixAndSuffixBackTick

func TrimAllPrefixAndSuffixBackTick(raw string) string

去除字符串所有[`]前缀和[`]后缀

func TrimAllPrefixAndSuffixPoint

func TrimAllPrefixAndSuffixPoint(raw string) string

去除字符串所有[.]前缀和[.]后缀

func TrimAllPrefixAndSuffixSlash

func TrimAllPrefixAndSuffixSlash(raw string) string

去除字符串所有[/]前缀和[/]后缀

func TrimAllPrefixAndSuffixSpace

func TrimAllPrefixAndSuffixSpace(raw string) string

去除字符串所有空格前缀和空格后缀

func TrimAllPrefixAndSuffixSymbol

func TrimAllPrefixAndSuffixSymbol(raw string, symbol string) string

指定去除字符串所有前缀和后缀

func TrimAllPrefixAsterisk

func TrimAllPrefixAsterisk(raw string) string

去除字符串所有[*]前缀

func TrimAllPrefixBackSlash

func TrimAllPrefixBackSlash(raw string) string

去除字符串所有[\]前���

func TrimAllPrefixBackTick

func TrimAllPrefixBackTick(raw string) string

去除字符串所有[`]前缀

func TrimAllPrefixPoint

func TrimAllPrefixPoint(raw string) string

去除字符串所有[.]前缀

func TrimAllPrefixSlash

func TrimAllPrefixSlash(raw string) string

去除字符串所有[/]前缀

func TrimAllPrefixSpace

func TrimAllPrefixSpace(raw string) string

去除字符串所有空格前缀

func TrimAllPrefixSymbol

func TrimAllPrefixSymbol(raw string, symbol string) string

指定去除字符串所有前缀

func TrimAllSpace

func TrimAllSpace(raw string) string

去除字符串所有空格

func TrimAllSuffixAsterisk

func TrimAllSuffixAsterisk(raw string) string

去除字符串所有[*]后缀

func TrimAllSuffixBackSlash

func TrimAllSuffixBackSlash(raw string) string

去除字符串所有[\]后缀

func TrimAllSuffixBackTick

func TrimAllSuffixBackTick(raw string) string

去除字符串所有[`]后缀

func TrimAllSuffixPoint

func TrimAllSuffixPoint(raw string) string

去除字符串所有[.]后缀

func TrimAllSuffixSlash

func TrimAllSuffixSlash(raw string) string

去除字符串所有[/]后缀

func TrimAllSuffixSpace

func TrimAllSuffixSpace(raw string) string

去除字符串所有空格后缀

func TrimAllSuffixSymbol

func TrimAllSuffixSymbol(raw string, symbol string) string

指定去除字符串所有后缀

func UintToIP

func UintToIP(n uint32) net.IP

UintToIP 将 uint32 转换回 IP 地址

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 Validate

func Validate(object any, language string) error

func ValidateNil

func ValidateNil(object any) bool

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 Duration

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

Duration of iso8601

func NewDuration

func NewDuration(years, months, days, hours, minutes, seconds string) (*Duration, error)

NewDuration return duration

func (Duration) ISO8601Duration

func (duration Duration) ISO8601Duration() string

ISO8601Duration to string

type NetworkInterfaceInfo

type NetworkInterfaceInfo struct {
	Name         string
	HardwareAddr string
	IPNetworks   []*net.IPNet
	Iface        *net.Interface
}

NetworkInterfaceInfo 存储网络接口信息

func GetAvailableNetworkInterfaces

func GetAvailableNetworkInterfaces(includeIPv6 bool) ([]NetworkInterfaceInfo, error)

GetAvailableNetworkInterfaces 获取所有可用网络接口信息: 跳过回环接口和未启用的接口

type ScanResult

type ScanResult struct {
	IP        net.IP
	Port      uint
	Address   string
	Mac       string
	Reachable bool
	Latency   time.Duration
}

ScanResult 存储扫描结果

func CheckIPPortReachable

func CheckIPPortReachable(ip net.IP, port uint, timeout time.Duration) (result ScanResult, err error)

CheckIPPortReachable 检查 IP:port 是否可达

func CheckIPReachable

func CheckIPReachable(ip net.IP, ports []uint, timeout time.Duration) (result []ScanResult)

CheckIPReachable 检查 IP 是否可达

func PingIP

func PingIP(ip net.IP, timeout time.Duration) ScanResult

PingIP 使用 ICMP 进行更准确的连通性检测(需要权限)

func ScanNetworkInterface

func ScanNetworkInterface(ifaceInfo NetworkInterfaceInfo, ports []uint, timeout time.Duration) []ScanResult

ScanNetworkInterface 扫描网络接口的子网 IP

type XSDuration

type XSDuration struct {
	Negative bool
	Years    int
	Months   int
	Days     int
	Hours    int
	Minutes  int
	Seconds  float64
}

XSDuration 表示 xs:duration 类型

func ParseXSDuration

func ParseXSDuration(durationStr string) (XSDuration, error)

ParseXSDuration 解析 xs:duration 字符串

func (XSDuration) String

func (d XSDuration) String() string

String 返回 XSDuration 的字符串表示

func (XSDuration) ToDuration

func (d XSDuration) ToDuration() time.Duration

ToDuration 将 XSDuration 转换为 time.Duration 注意:此方法会忽略年和月,因为它们无法精确转换为固定的时间长度