Documentation
¶
Index ¶
- func AESDecrypt(ciphertext []byte, key []byte) ([]byte, error)
- func AESEncrypt(plaintext []byte, key []byte) ([]byte, error)
- func AddDays(t time.Time, days int) time.Time
- func AddMonths(t time.Time, months int) time.Time
- func AddYears(t time.Time, years int) time.Time
- func AppendToFile(path string, content string) error
- func Base64Decode(text string) ([]byte, error)
- func Base64Encode(data []byte) string
- func CamelCase(str string) string
- func Capitalize(str string) string
- func Ceil(x float64, precision int) float64
- func Chunk[T any](arr []T, size int) [][]T
- func Clamp[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64](value, min, max T) T
- func CleanDirectory(path string) error
- func Clear[K comparable, V any](m map[K]V)
- func Clone[K comparable, V any](m map[K]V) map[K]V
- func CompareHashes(hash1, hash2 string) bool
- func CompareVersion(v1, v2 string) int
- func Contains[T comparable](arr []T, target T) bool
- func CopyDirectory(src, dst string) error
- func CopyFile(src, dst string) error
- func Count[T any](arr []T, predicate func(T) bool) int
- func CountMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) int
- func CountWords(str string) int
- func CreateDirIfNotExists(path string) error
- func CreateDirectory(path string) error
- func DecryptString(ciphertext string, key []byte) (string, error)
- func DeleteFile(path string) error
- func Difference[T comparable](arr1 []T, arr2 []T) []T
- func DirExists(path string) bool
- func Distance(x1, y1, x2, y2 float64) float64
- func EncryptString(plaintext string, key []byte) (string, error)
- func Entries[K comparable, V any](m map[K]V) [][2]interface{}
- func Every[T any](arr []T, predicate func(T) bool) bool
- func EveryMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
- func ExtractEmails(text string) []string
- func ExtractURLs(text string) []string
- func Factorial(n int) int
- func FileExists(path string) bool
- func Filter[T any](arr []T, predicate func(T) bool) []T
- func FilterMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) map[K]V
- func Find[T any](arr []T, predicate func(T) bool) (T, bool)
- func FindInMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) (K, V, bool)
- func FindIndex[T any](arr []T, predicate func(T) bool) int
- func Flatten[T any](arr [][]T) []T
- func Floor(x float64, precision int) float64
- func ForEach[K comparable, V any](m map[K]V, fn func(K, V))
- func FormatCurrency(amount float64, currency string) string
- func FormatDuration(d time.Duration) string
- func FormatFileSize(size int64) string
- func FormatPercent(value float64) string
- func FormatTemplate(template string, data map[string]interface{}) string
- func FormatThousands(n int64) string
- func FormatTime(t time.Time, layout string) string
- func FromEntries[K comparable, V any](entries [][2]interface{}) map[K]V
- func GCD(a, b int) int
- func GenerateAESKey(bits int) ([]byte, error)
- func GenerateRandomBytes(length int) ([]byte, error)
- func GenerateRandomString(length int) (string, error)
- func GetAge(birthDate time.Time) int
- func GetCurrentMicroseconds() int64
- func GetCurrentMilliseconds() int64
- func GetCurrentNanoseconds() int64
- func GetCurrentTime() time.Time
- func GetCurrentTimestamp() int64
- func GetDaysInMonth(year int, month time.Month) int
- func GetDirectoryOwner(path string) (uint32, uint32, error)
- func GetDirectoryPermissions(path string) (os.FileMode, error)
- func GetDirectorySize(path string) (int64, error)
- func GetEndOfDay(t time.Time) time.Time
- func GetEndOfMonth(t time.Time) time.Time
- func GetEndOfQuarter(t time.Time) time.Time
- func GetEndOfWeek(t time.Time) time.Time
- func GetEndOfYear(t time.Time) time.Time
- func GetFileExtension(path string) string
- func GetFileMD5(path string) (string, error)
- func GetFileModTime(path string) (int64, error)
- func GetFileName(path string) string
- func GetFileOwner(path string) (uint32, uint32, error)
- func GetFilePermissions(path string) (os.FileMode, error)
- func GetFileSize(path string) (int64, error)
- func GetFiles(path string) ([]string, error)
- func GetFilesWithExtension(path string, ext string) ([]string, error)
- func GetOrCompute[K comparable, V any](m map[K]V, key K, computer func() V) V
- func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V
- func GetOrSet[K comparable, V any](m map[K]V, key K, defaultValue V) V
- func GetQuarter(t time.Time) int
- func GetStartOfDay(t time.Time) time.Time
- func GetStartOfMonth(t time.Time) time.Time
- func GetStartOfQuarter(t time.Time) time.Time
- func GetStartOfWeek(t time.Time) time.Time
- func GetStartOfYear(t time.Time) time.Time
- func GetSubdirectories(path string) ([]string, error)
- func GetWeekday(t time.Time) string
- func GroupBy[T any, K comparable](arr []T, keySelector func(T) K) map[K][]T
- func GroupByMap[K comparable, V any, G comparable](m map[K]V, keySelector func(K, V) G) map[G]map[K]V
- func HasKey[K comparable, V any](m map[K]V, key K) bool
- func HasValue[K comparable, V comparable](m map[K]V, value V) bool
- func HashPassword(password string) string
- func IndexOf[T comparable](arr []T, target T) int
- func Intersection[T comparable](arrs ...[]T) []T
- func Invert[K comparable, V comparable](m map[K]V) map[V]K
- func IsBinaryFile(path string) bool
- func IsEmail(email string) bool
- func IsEmptyDirectory(path string) (bool, error)
- func IsLeapYear(year int) bool
- func IsNumeric(s string) bool
- func IsPrime(n int) bool
- func IsSameDay(t1, t2 time.Time) bool
- func IsSameMonth(t1, t2 time.Time) bool
- func IsSameQuarter(t1, t2 time.Time) bool
- func IsSameWeek(t1, t2 time.Time) bool
- func IsSameYear(t1, t2 time.Time) bool
- func IsTextFile(path string) bool
- func IsURL(url string) bool
- func KebabCase(str string) string
- func Keys[K comparable, V any](m map[K]V) []K
- func LCM(a, b int) int
- func LastIndexOf[T comparable](arr []T, target T) int
- func Lerp(start, end, t float64) float64
- func ListDirectory(path string) ([]string, error)
- func ListDirectoryWithFilter(path string, filter func(string) bool) ([]string, error)
- func MD5(str string) string
- func MD5Hash(text string) string
- func Map[T any, U any](arr []T, mapper func(T) U) []U
- func MapMap[K comparable, V any, U any](m map[K]V, mapper func(K, V) U) map[K]U
- func Max[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64](x, y T) T
- func Merge[K comparable, V any](maps ...map[K]V) map[K]V
- func Min[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64](x, y T) T
- func MoveDirectory(src, dst string) error
- func MoveFile(src, dst string) error
- func Omit[K comparable, V any](m map[K]V, keys []K) map[K]V
- func ParseFloat(s string, defaultVal float64) float64
- func ParseInt(s string, defaultVal int) int
- func ParseTime(timeStr, layout string) (time.Time, error)
- func ParseVersion(version string) (major, minor, patch int, err error)
- func Pick[K comparable, V any](m map[K]V, keys []K) map[K]V
- func RandomFloat(min, max float64) float64
- func RandomInt(min, max int) int
- func RandomString(length int) string
- func ReadFile(path string) (string, error)
- func ReadLines(path string) ([]string, error)
- func Reduce[T any, U any](arr []T, reducer func(U, T) U, initial U) U
- func Remove[T comparable](arr []T, target T) []T
- func RemoveAll[T comparable](arr []T, target T) []T
- func RemoveAt[T any](arr []T, index int) []T
- func RemoveDirectory(path string) error
- func RemoveSpaces(str string) string
- func Reverse[T any](arr []T) []T
- func ReverseString(str string) string
- func Round(x float64, precision int) float64
- func SHA1Hash(text string) string
- func SHA256Hash(text string) string
- func SHA512Hash(text string) string
- func SetDirectoryOwner(path string, uid, gid int) error
- func SetDirectoryPermissions(path string, mode os.FileMode) error
- func SetFileOwner(path string, uid, gid int) error
- func SetFilePermissions(path string, mode os.FileMode) error
- func Shuffle[T any](arr []T) []T
- func Slugify(str string) string
- func SnakeCase(str string) string
- func Some[T any](arr []T, predicate func(T) bool) bool
- func SomeMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
- func Sort[T any](arr []T, less func(i, j T) bool) []T
- func ToFixed(num float64, precision int) string
- func TruncateString(str string, length int) string
- func Union[T comparable](arrs ...[]T) []T
- func Unique[T comparable](arr []T) []T
- func Update[K comparable, V any](m map[K]V, key K, updater func(V) V) bool
- func Values[K comparable, V any](m map[K]V) []V
- func VerifyPassword(password, hashedPassword string) bool
- func WrapText(text string, width int) string
- func WriteFile(path string, content string) error
- func WriteLines(path string, lines []string) error
- func Zip[T any](arrs ...[]T) [][]T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountMap ¶
func CountMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) int
Count 统计满足条件的键值对个数
func CreateDirIfNotExists ¶
CreateDirIfNotExists 如果目录不存在则创建
func DecryptString ¶
DecryptString 解密字符串
func EncryptString ¶
EncryptString 加密字符串
func EveryMap ¶
func EveryMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
Every 检查是否所有键值对都满足条件
func FilterMap ¶
func FilterMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) map[K]V
Filter 过滤map
func FindInMap ¶
func FindInMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) (K, V, bool)
Find 查找满足条件的第一个键值对
func FormatCurrency ¶
FormatCurrency 格式化货币
func FormatTemplate ¶
FormatTemplate 简单的模板格式化
func FromEntries ¶
func FromEntries[K comparable, V any](entries [][2]interface{}) map[K]V
FromEntries 从键值对数组创建map
func GenerateRandomBytes ¶
GenerateRandomBytes 生成指定长度的随机字节数组
func GenerateRandomString ¶
GenerateRandomString 生成指定长度的随机字符串
func GetDirectoryOwner ¶
GetDirectoryOwner 获取目录所有者
func GetDirectoryPermissions ¶
GetDirectoryPermissions 获取目录权限
func GetFilePermissions ¶
GetFilePermissions 获取文件权限
func GetFilesWithExtension ¶
GetFilesWithExtension 获取指定扩展名的文件
func GetOrCompute ¶
func GetOrCompute[K comparable, V any](m map[K]V, key K, computer func() V) V
GetOrCompute 获取map中的值,如果不存在则计算、设置并返回新值
func GetOrDefault ¶
func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V
GetOrDefault 获取map中的值,如果不存在则返回默认值
func GetOrSet ¶
func GetOrSet[K comparable, V any](m map[K]V, key K, defaultValue V) V
GetOrSet 获取map中的值,如果不存在则设置并返回默认值
func GetSubdirectories ¶
GetSubdirectories 获取所有子目录
func GroupBy ¶
func GroupBy[T any, K comparable](arr []T, keySelector func(T) K) map[K][]T
GroupBy 按条件对数组元素进行分组
func GroupByMap ¶
func GroupByMap[K comparable, V any, G comparable](m map[K]V, keySelector func(K, V) G) map[G]map[K]V
GroupBy 按条件对map进行分组
func HasValue ¶
func HasValue[K comparable, V comparable](m map[K]V, value V) bool
HasValue 检查map是否包含指定的值
func LastIndexOf ¶
func LastIndexOf[T comparable](arr []T, target T) int
LastIndexOf 获取元素在数组中最后出现的索引
func ListDirectoryWithFilter ¶
ListDirectoryWithFilter 列出目录内容(带过滤器)
func MapMap ¶
func MapMap[K comparable, V any, U any](m map[K]V, mapper func(K, V) U) map[K]U
Map 映射map
func ParseVersion ¶
ParseVersion 解析版本号
func SetDirectoryOwner ¶
SetDirectoryOwner 设置目录所有者
func SetDirectoryPermissions ¶
SetDirectoryPermissions 设置目录权限
func SetFilePermissions ¶
SetFilePermissions 设置文件权限
func SomeMap ¶
func SomeMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
Some 检查是否存在键值对满足条件
func TruncateString ¶
TruncateString 截断字符串到指定长度,并添加省略号
func Update ¶
func Update[K comparable, V any](m map[K]V, key K, updater func(V) V) bool
Update 更新map中的值
Types ¶
This section is empty.