goutils

package
v0.0.0-...-42ebea8 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 17 Imported by: 4

Documentation

Index

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 Base58Decode

func Base58Decode(input []byte) []byte

Base58Decode 解码

func Base58Encode

func Base58Encode(input []byte) []byte

Base58Encode 编码

func Bool

func Bool(value any) bool

Bool 真值测试

func ContainsAny

func ContainsAny(str string, in []string) bool

func CutRune

func CutRune(str string, n int) string

func DecodeUint64

func DecodeUint64(v string) uint64

func DecryptUID

func DecryptUID(s string) (uint64, error)

func EncodeUint64

func EncodeUint64(u uint64) string

func EncryptUID

func EncryptUID(u uint64) string

func GenerateSerialNumber

func GenerateSerialNumber(mix uint64) string

func IsValidPath

func IsValidPath(path string) bool

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 Mask

func Mask(str string, head, tail int) string

func RandLowerStr

func RandLowerStr(n int) string

func RandStr

func RandStr(n int) string

func RandomBase33String

func RandomBase33String(length int) string

func ReverseBytes

func ReverseBytes(data []byte)

ReverseBytes 翻转字节

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 SliceFilter

func SliceFilter[T any](objs []T, filter func(T) bool) []T

SliceFilter 过滤切片

func SliceIndex

func SliceIndex[T any, K comparable, V any](objs []T, primaryKey func(T) (K, V)) map[K][]V

SliceIndex 将切片转换成以主键为key的map,值为切片

func SliceJoin

func SliceJoin[T any](list []T, separator string) string

SliceJoin 将任意数值类型的slice切片转换成 用 , 拼接起来的字符串

func SliceUnique

func SliceUnique[T any, S comparable](objs []T, primaryKey func(T) S) []S

func Split

func Split(str string) []string

func SplitHostPort

func SplitHostPort(addr string) (string, int, error)

func SplitUnsigned

func SplitUnsigned[T constraints.Unsigned](str string) []T

func Struct2Map

func Struct2Map[T any](obj T, exclude ...string) (map[string]any, map[string]any)

Struct2Map 将结构体转成map,除去在exclude中声明的tag

func UsernameType

func UsernameType(username string) int

Types

This section is empty.

Jump to

Keyboard shortcuts

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