Documentation ¶
Index ¶
- Constants
- Variables
- func AesDecrypt(encryptedHex string, key []byte) (string, error)
- func AesEncrypt(plaintext string, key []byte) (string, error)
- func BitsToSubNetMask(maskBits int) (string, error)
- func CalculateNetwork(ipAddr, subnetMask string) (string, error)
- func ConcatStrings(parts ...string) string
- func CopySlice[T any](original []T) []T
- func DetectTcpPort(ip string, port int, timeout time.Duration) bool
- func GetCurrentTimestampMinute() int64
- func GetFilenameWithoutExt(filename string) string
- func HMACMD5Hash(text string, key string) string
- func HMACSHA1Hash(text string, key string) string
- func HMACSHA224Hash(text string, key string) string
- func HMACSHA256Hash(text string, key string) string
- func HMACSHA384Hash(text string, key string) string
- func HMACSHA512Hash(text string, key string) string
- func HMACSHA512_224Hash(text string, key string) string
- func HMACSHA512_256Hash(text string, key string) string
- func HttpDelete(apiUrl string, params map[string]string, timeout time.Duration) (int, error)
- func HttpGet(apiUrl string, params map[string]string, timeout time.Duration) ([]byte, int, error)
- func HttpHead(apiUrl string, params map[string]string, timeout time.Duration) (int, error)
- func HttpOptions(apiUrl string, timeout time.Duration) (http.Header, int, error)
- func HttpPatch(apiUrl string, params map[string]string, body any, timeout time.Duration) ([]byte, int, error)
- func HttpPost(apiUrl string, params map[string]string, body any, timeout time.Duration) ([]byte, int, error)
- func HttpPut(apiUrl string, params map[string]string, body any, timeout time.Duration) ([]byte, int, error)
- func HttpTrace(apiUrl string, timeout time.Duration) ([]byte, int, error)
- func IpToUint32(ipStr string) (uint32, error)
- func IsIPInCIDR(ip string, cidr string) bool
- func IsValidIP(ipAddr string) bool
- func IsValidPort(port string) (int, error)
- func IsValidURL(u string) bool
- func MD5Hash(text string, num int) string
- func MD5HashWithSalt(text, salt string, num int) string
- func MatchString(src, pattern string) bool
- func NowTimeMillisecond() string
- func NowTimeSecond() string
- func Ping(ip string, timeout time.Duration) (bool, error)
- func PingUseCommand(ipAddr string) (bool, error)
- func RemoveFirstString(slice []string) []string
- func RemoveItemsContainingSubstring(arr []string, substr string) []string
- func RemoveItemsNotContainingSubstring(arr []string, substr string) []string
- func RemoveMatchString(slice []string, pattern string, method int) []string
- func RemoveMultiSpaces(str string) string
- func RemoveTextWithinMatch(str string, pattern string, method int) string
- func RemoveTextWithinParens(str string) string
- func SHA1Hash(text string) string
- func SHA224Hash(text string) string
- func SHA256Hash(text string) string
- func SHA384Hash(text string) string
- func SHA512Hash(text string) string
- func SHA512_224Hash(text string) string
- func SHA512_256Hash(text string) string
- func SecondsToHuman(input int64) string
- func SortStructs[T any](slice []T, fieldName string, ascending bool) error
- func StringEndWith(str, suffix string) bool
- func StringEndWithIgnoreCase(str, suffix string) bool
- func StringIsEmpty(str string) bool
- func StringIsInt(str string) (int, bool)
- func StringIsInt64(str string) (int64, bool)
- func StringStartWith(str, prefix string) bool
- func StringStartWithIgnoreCase(str, prefix string) bool
- func StringToLocalTime(timeStr string) (time.Time, error)
- func SubNetMaskToBits(subnetMask string) (int, error)
- func TimeToTimestamp(t time.Time, precision int) int64
- func TimestampToTime(ts int64, precision int) time.Time
- func TrimLeadingCharacter(str, character string) string
- func TrimLeadingCharacterIgnoreCase(str, character string) string
- func TrimTrailingCharacter(str, character string) string
- func TrimTrailingCharacterIgnoreCase(str, character string) string
- func Uint32ToIP(ipInt uint32) string
- func ValidateAndConvertCIDR(cidr string) uint32
- type SlicePagination
Constants ¶
const ( TIME_PRECISION_SECOND = iota // 定义秒精度常量 TIME_PRECISION_MILLISECOND = iota // 定义毫秒精度常量 TIME_PRECISION_MICROSECOND = iota // 定义微秒精度常量 TIME_PRECISION_NANOSECOND = iota // 定义纳秒精度常量 )
Variables ¶
var ( ExecFilename string // 可执行文件名 ExecPath string // 可执行文件路径 LocalDir string // 可执行文件所在目录 )
Functions ¶
func AesDecrypt ¶ added in v0.1.5
AesDecrypt Aes解密
func AesEncrypt ¶ added in v0.1.5
AesEncrypt Aes加密
func BitsToSubNetMask ¶ added in v0.1.8
BitsToSubNetMask 将掩码位数转换为子网掩码 传入 24,返回 255.255.255.0
func CalculateNetwork ¶ added in v0.1.8
CalculateNetwork 根据给定的IP地址和子网掩码计算网络地址 传入 192.168.1.1 和 255.255.255.0,返回 192.168.1.0/24
func ConcatStrings ¶ added in v0.2.8
ConcatStrings 使用strings.Builder高效地拼接多个字符串
func CopySlice ¶ added in v0.3.2
func CopySlice[T any](original []T) []T
CopySlice 复制切片为不同的引用(深拷贝) T为切片元素
func DetectTcpPort ¶ added in v0.1.3
DetectTcpPort 检测Tcp端口是否开通
func GetCurrentTimestampMinute ¶ added in v0.6.0
func GetCurrentTimestampMinute() int64
GetCurrentTimestampMinute 获取当前时间的整数分钟,返回Unix时间戳秒数
func GetFilenameWithoutExt ¶ added in v0.7.3
GetFilenameWithoutExt 返回不带扩展名的文件名。
func HMACMD5Hash ¶ added in v0.1.5
HMACMD5Hash 将字符串用HMAC-MD5编码后返回
func HMACSHA1Hash ¶ added in v0.1.5
HMACSHA1Hash 将字符串用HMAC-SHA1编码后返回
func HMACSHA224Hash ¶ added in v0.1.5
HMACSHA224Hash 将字符串用HMAC-SHA224编码后返回
func HMACSHA256Hash ¶ added in v0.1.5
HMACSHA256Hash 将字符串用HMAC-SHA256编码后返回
func HMACSHA384Hash ¶ added in v0.1.5
HMACSHA384Hash 将字符串用HMAC-SHA384编码后返回
func HMACSHA512Hash ¶ added in v0.1.5
HMACSHA512Hash 将字符串用HMAC-SHA512编码后返回
func HMACSHA512_224Hash ¶ added in v0.1.5
HMACSHA512_224Hash 将字符串用HMAC-SHA512/224编码后返回
func HMACSHA512_256Hash ¶ added in v0.1.5
HMACSHA512_256Hash 将字符串用HMAC-SHA512/256编码后返回
func HttpDelete ¶ added in v0.4.7
HttpDelete 发送一个DELETE请求。 返回状态码和错误信息
func HttpOptions ¶ added in v0.4.7
HttpOptions 发送一个OPTIONS请求。 返回响应头、状态码和错误信息
func HttpPatch ¶ added in v0.4.7
func HttpPatch(apiUrl string, params map[string]string, body any, timeout time.Duration) ([]byte, int, error)
HttpPatch 发送一个带有JSON格式body的PATCH请求。 返回响应体、状态码和错误信息
func HttpPost ¶ added in v0.3.8
func HttpPost(apiUrl string, params map[string]string, body any, timeout time.Duration) ([]byte, int, error)
HttpPost 发送一个带有JSON格式body的POST请求。 返回响应体、状态码和错误信息
func HttpPut ¶ added in v0.4.7
func HttpPut(apiUrl string, params map[string]string, body any, timeout time.Duration) ([]byte, int, error)
HttpPut 发送一个带有JSON格式body的PUT请求。 返回响应体、状态码和错误信息
func IpToUint32 ¶ added in v0.3.9
IpToUint32 将IP地址转换为整数 传入 192.168.1.1,返回 3232235777
func IsIPInCIDR ¶ added in v0.5.7
IsIPInCIDR 判断IP地址是否在CIDR网段内 传入 192.168.1.1 和 192.168.0.0/16,返回 true
func MD5HashWithSalt ¶ added in v0.1.5
MD5HashWithSalt 将字符串用MD5编码后返回,并可以添加盐值
func MatchString ¶ added in v0.1.7
MatchString 检查正则表达式是否与给定的源字符串匹配。
func NowTimeMillisecond ¶ added in v0.1.6
func NowTimeMillisecond() string
NowTimeMillisecond 获取当前时间,格式为:2006-01-02 15:04:05.0000
func NowTimeSecond ¶ added in v0.1.6
func NowTimeSecond() string
NowTimeSecond 获取当前时间,格式为:2006-01-02 15:04:05
func PingUseCommand ¶ added in v0.7.4
PingUseCommand 使用系统ping命令 对目的地址发起ping检测icmp是否通畅(只支持ipv4)
func RemoveFirstString ¶ added in v0.1.8
RemoveFirstString 从字符串数组切片里移除第一个元素
func RemoveItemsContainingSubstring ¶ added in v0.1.1
RemoveItemsContainingSubstring 从字符串数组切片里移除包含substr字符串的项并移除连续空格字符
func RemoveItemsNotContainingSubstring ¶ added in v0.1.1
RemoveItemsNotContainingSubstring 从字符串数组切片里移除不包含substr字符串的项并移除连续空格字符
func RemoveMatchString ¶ added in v0.1.9
RemoveMatchString 按正则表达式移除字符串数组切片中的元素 method为1则移除匹配项 method为2则移除不匹配项
func RemoveMultiSpaces ¶ added in v0.1.1
RemoveMultiSpaces 从字符串中移除多个连续空格字符
func RemoveTextWithinMatch ¶ added in v0.2.0
RemoveTextWithinMatch 按正则表达式移除字符串中的行 method为1则移除匹配项 method为2则移除不匹配项
func RemoveTextWithinParens ¶ added in v0.1.1
RemoveTextWithinParens 从字符串中删除括号内的文本。
func SHA512_224Hash ¶ added in v0.1.5
SHA512_224Hash 将字符串用SHA512/224编码后返回
func SHA512_256Hash ¶ added in v0.1.5
SHA512_256Hash 将字符串用SHA512/256编码后返回
func SecondsToHuman ¶ added in v0.5.3
SecondsToHuman 将秒转换为天、小时、分钟和秒的字符串
func SortStructs ¶ added in v0.3.3
SortStructs 对结构体切片进行排序 T为结构体
func StringEndWith ¶ added in v0.1.7
StringEndWith 检查字符串是否以指定的后缀结尾。
func StringEndWithIgnoreCase ¶ added in v0.1.7
StringEndWithIgnoreCase 检查字符串是否以指定的后缀结尾,忽略大小写。
func StringIsInt ¶ added in v0.1.6
StringIsInt 检查字符串是否是一个整数。
func StringIsInt64 ¶ added in v0.1.6
StringIsInt64 检查字符串是否是一个64位整数。
func StringStartWith ¶ added in v0.1.7
StringStartWith 检查字符串是否以指定的前缀开头。
func StringStartWithIgnoreCase ¶ added in v0.1.7
StringStartWithIgnoreCase 检查字符串是否以指定的前缀开头,忽略大小写。
func StringToLocalTime ¶ added in v0.2.5
StringToLocalTime 字符串转换为本地时间
func SubNetMaskToBits ¶ added in v0.1.8
SubNetMaskToBits 将子网掩码转换为掩码位数 传入 255.255.255.0,返回 24
func TimeToTimestamp ¶ added in v0.2.2
TimeToTimestamp 根据指定的精度将 time.Time 转换为时间戳
func TimestampToTime ¶ added in v0.2.2
TimestampToTime 根据指定的精度将时间戳转换回 time.Time
func TrimLeadingCharacter ¶ added in v0.1.7
TrimLeadingCharacter 从字符串中删除前导字符。
func TrimLeadingCharacterIgnoreCase ¶ added in v0.1.7
TrimLeadingCharacterIgnoreCase 从字符串中删除前导字符,忽略大小写。
func TrimTrailingCharacter ¶ added in v0.1.7
TrimTrailingCharacter 从字符串中删除尾随字符。
func TrimTrailingCharacterIgnoreCase ¶ added in v0.1.7
TrimTrailingCharacterIgnoreCase 从字符串中删除尾随字符,忽略大小写。
func Uint32ToIP ¶ added in v0.3.9
Uint32ToIP 将整数转换为IP地址 传入 3232235777,返回 192.168.1.1
func ValidateAndConvertCIDR ¶ added in v0.5.4
ValidateAndConvertCIDR 验证CIDR是否合法,并转换网络地址为uint32 传入 192.168.1.1/24,返回 3232235776
Types ¶
type SlicePagination ¶ added in v0.3.4
type SlicePagination[T any] struct { Page int // 当前页 PageSize int // 每页条数 Total int // 总条数 TotalPages int // 总页数 Items []T // 当前页的数据 HasPrevPage bool // 是否有上一页 HasNextPage bool // 是否有下一页 }
SlicePagination 表示包含所有必要元数据的分页结果。
func PaginateSlice ¶ added in v0.3.4
func PaginateSlice[T any](items []T, page, pageSize int) SlicePagination[T]
PaginateSlice 获取任何类型的切片、页码和页面大小,并返回 SlicePagination.