Documentation
¶
Index ¶
- Constants
- Variables
- func Base58Decode(input []byte) []byte
- func Base58Encode(input []byte) []byte
- func Bool(value any) bool
- func ContainsAny(str string, in []string) bool
- func CutRune(str string, n int) string
- func DecodeUint64(v string) uint64
- func DecryptUID(s string) (uint64, error)
- func EncodeUint64(u uint64) string
- func EncryptUID(u uint64) string
- func GenerateSerialNumber(mix uint64) string
- func IsValidPath(path string) bool
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MapValues[K comparable, V any](m map[K]V) []V
- func Mask(str string, head, tail int) string
- func RandLowerStr(n int) string
- func RandStr(n int) string
- func RandomBase33String(length int) string
- func ReverseBytes(data []byte)
- func Slice2KV[T any, K comparable, V any](objs []T, first bool, primaryKey func(T, int) (K, V)) map[K]V
- func Slice2Map[T any, K comparable](objs []T, first bool, primaryKey func(T) K) map[K]T
- func SliceColumns[T any, S comparable](objs []T, primaryKey func(T) S) []S
- func SliceFilter[T any](objs []T, filter func(T) bool) []T
- func SliceIndex[T any, K comparable, V any](objs []T, primaryKey func(T) (K, V)) map[K][]V
- func SliceJoin[T any](list []T, separator string) string
- func SliceUnique[T any, S comparable](objs []T, primaryKey func(T) S) []S
- func Split(str string) []string
- func SplitHostPort(addr string) (string, int, error)
- func SplitUnsigned[T constraints.Unsigned](str string) []T
- func Struct2Map[T any](obj T, exclude ...string) (map[string]any, map[string]any)
- func UsernameType(username string) int
Constants ¶
View Source
const ( TypeUnknown = iota TypeEmail TypeMobile TypeId TypeName )
Variables ¶
View Source
var ( EmailRegex = regexp.MustCompile(`^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$`) MobileRegex = regexp.MustCompile(`^1[345789]\d{9}$`) DigitRegex = regexp.MustCompile(`^\d{1,20}$`) LetterRegex = regexp.MustCompile(`^[a-zA-Z]\w+$`) MD5Regex = regexp.MustCompile(`^[0-9a-fA-F]{32}$`) )
View Source
var DBC2SBC = unicode.SpecialCase{ unicode.CaseRange{ Lo: 0x3002, Hi: 0x3002, Delta: [unicode.MaxCase]rune{ 0, 0x002e - 0x3002, 0, }, }, unicode.CaseRange{ Lo: 0xFF01, Hi: 0xFF19, Delta: [unicode.MaxCase]rune{ 0, 0x0021 - 0xFF01, 0, }, }, }
View Source
var (
ErrInvalidAddr = errors.New("invalid addr")
)
Functions ¶
func ContainsAny ¶
func DecodeUint64 ¶
func DecryptUID ¶
func EncodeUint64 ¶
func EncryptUID ¶
func GenerateSerialNumber ¶
func IsValidPath ¶
IsValidPath checks if the path is valid for either Linux or Windows.
func MapKeys ¶
func MapKeys[K comparable, V any](m map[K]V) []K
func MapValues ¶
func MapValues[K comparable, V any](m map[K]V) []V
func RandLowerStr ¶
func RandomBase33String ¶
func Slice2KV ¶
func Slice2KV[T any, K comparable, V any](objs []T, first bool, primaryKey func(T, int) (K, V)) map[K]V
func Slice2Map ¶
func Slice2Map[T any, K comparable](objs []T, first bool, primaryKey func(T) K) map[K]T
将某个结构体的slice,转换成指定主键的map 如 [{id:1,name:2}, {id:2,name:3}] 转换成 {1:{id:1,name:2}, 2:{id:2,name:3}} 可用于将数据库的查询结果转成map,便于后续使用 注意这里的primarykey是结构体字段的名字而不是tag
func SliceColumns ¶
func SliceColumns[T any, S comparable](objs []T, primaryKey func(T) S) []S
SliceColumns 获取切片每个元素中的指定值组成的新切片
func SliceIndex ¶
func SliceIndex[T any, K comparable, V any](objs []T, primaryKey func(T) (K, V)) map[K][]V
SliceIndex 将切片转换成以主键为key的map,值为切片
func SliceUnique ¶
func SliceUnique[T any, S comparable](objs []T, primaryKey func(T) S) []S
func SplitUnsigned ¶
func SplitUnsigned[T constraints.Unsigned](str string) []T
func Struct2Map ¶
Struct2Map 将结构体转成map,除去在exclude中声明的tag
func UsernameType ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.