utils

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Second = 1
	Minute = 60 * Second
	Hour   = 60 * Minute
	Day    = 24 * Hour
	Week   = 7 * Day
)

Constants for time durations | 时间常量

View Source
const (
	DefaultSeparator = ","
	WildcardChar     = "*"
)

Constants for string operations | 字符串操作常量

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(s string) (string, error)

Base64Decode Decodes base64 string | Base64解码

func Base64Encode

func Base64Encode(s string) string

Base64Encode Encodes string to base64 | Base64编码

func Base64URLDecode

func Base64URLDecode(s string) (string, error)

Base64URLDecode Decodes URL-safe base64 string | URL安全的Base64解码

func Base64URLEncode

func Base64URLEncode(s string) string

Base64URLEncode Encodes string to URL-safe base64 | URL安全的Base64编码

func ContainsString

func ContainsString(slice []string, item string) bool

ContainsString checks if string slice contains item | 检查字符串数组是否包含指定字符串

func DefaultString

func DefaultString(s, defaultValue string) string

DefaultString returns default value if string is empty | 如果字符串为空则返回默认值

func FilterStrings

func FilterStrings(slice []string, predicate func(string) bool) []string

FilterStrings filters string slice by predicate | 根据条件过滤字符串数组

func FormatDuration

func FormatDuration(seconds int64) string

FormatDuration Formats duration in seconds to human-readable format | 格式化时间段(秒)为人类可读格式

func GetStructTag

func GetStructTag(field reflect.StructField, tag string) string

GetStructTag 获取结构体字段的标签值

func HasLength

func HasLength(s string, min, max int) bool

HasLength Checks if string length is within range | 检查字符串长度是否在范围内

func InSlice

func InSlice[T comparable](slice []T, val T) bool

InSlice Checks if value exists in slice | 检查值是否存在于切片中

func IsAlphanumeric

func IsAlphanumeric(s string) bool

IsAlphanumeric Checks if string contains only alphanumeric characters | 检查是否只包含字母数字

func IsEmpty

func IsEmpty(s string) bool

IsEmpty checks if string is empty | 检查字符串是否为空

func IsNotEmpty

func IsNotEmpty(s string) bool

IsNotEmpty checks if string is not empty | 检查字符串是否不为空

func IsNumeric

func IsNumeric(s string) bool

IsNumeric Checks if string contains only numbers | 检查是否只包含数字

func JoinNonEmpty

func JoinNonEmpty(sep string, strs ...string) string

JoinNonEmpty Joins non-empty strings | 连接非空字符串

func MapStrings

func MapStrings(slice []string, mapper func(string) string) []string

MapStrings applies function to each string in slice | 对数组中每个字符串应用函数

func MatchPattern

func MatchPattern(pattern, str string) bool

MatchPattern Pattern matching with wildcard support | 模式匹配(支持通配符*)

func MergeStrings

func MergeStrings(slices ...[]string) []string

MergeStrings Merges multiple string slices and removes duplicates | 合并多个字符串数组并去重

func ParseDuration

func ParseDuration(duration string) int64

ParseDuration Parses human-readable duration to seconds | 解析人类可读的时间段为秒

func ParsePermissionTag

func ParsePermissionTag(tag string) []string

ParsePermissionTag 解析权限标签 格式: "perm:user:read,user:write"

func ParseRoleTag

func ParseRoleTag(tag string) []string

ParseRoleTag 解析角色标签 格式: "role:admin,manager"

func RandomAlphanumeric

func RandomAlphanumeric(length int) string

RandomAlphanumeric generates random alphanumeric string | 生成随机字母数字字符串

func RandomNumericString

func RandomNumericString(length int) string

RandomNumericString generates random numeric string | 生成随机数字字符串

func RandomString

func RandomString(length int) string

RandomString generates random string of specified length | 生成指定长度的随机字符串

func RemoveString

func RemoveString(slice []string, item string) []string

RemoveString removes item from string slice | 从字符串数组中移除指定字符串

func SHA256Hash

func SHA256Hash(s string) string

SHA256Hash Generates SHA256 hash of string | 生成字符串的SHA256哈希

func SplitAndTrim

func SplitAndTrim(s, sep string) []string

SplitAndTrim Splits string and trims whitespace | 分割字符串并去除空格

func TimeToTimestamp

func TimeToTimestamp(t time.Time) int64

TimeToTimestamp Converts time.Time to Unix timestamp | time.Time转Unix时间戳

func TimestampToTime

func TimestampToTime(timestamp int64) time.Time

TimestampToTime Converts Unix timestamp to time.Time | Unix时间戳转time.Time

func ToBool

func ToBool(v any) (bool, error)

ToBool Converts any to bool | 将any转换为bool

func ToBytes

func ToBytes(value any) ([]byte, error)

ToBytes Converts any to bytes | 将any转换为字节

func ToInt

func ToInt(v any) (int, error)

ToInt Converts any to int | 将any转换为int

func ToInt64

func ToInt64(v any) (int64, error)

ToInt64 Converts any to int64 | 将any转换为int64

func ToString

func ToString(v any) string

ToString Converts any to string | 将any转换为string

func UniqueSlice

func UniqueSlice[T comparable](slice []T) []T

UniqueSlice Removes duplicates from slice | 去除切片中的重复元素

func UniqueStrings

func UniqueStrings(slice []string) []string

UniqueStrings removes duplicates from string slice | 字符串数组去重

Types

This section is empty.

Jump to

Keyboard shortcuts

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