util

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 28 Imported by: 23

Documentation

Index

Constants

View Source
const CSTLayout = "2006-01-02 15:04:05"
View Source
const CSTLayoutWithMillisecond = "2006-01-02 15:04:05.0000"

Variables

View Source
var (
	// Epoch is set to Oct 10 2010 10:10:10 UTC in milliseconds
	// You may customize this to set a different epoch for your application.
	Epoch int64 = 1286676610000

	// NodeBits holds the number of bits to use for SnowFlakeNode
	// Remember, you have a total 22 bits to share between SnowFlakeNode/Step
	NodeBits uint8 = 10

	// StepBits holds the number of bits to use for Step
	// Remember, you have a total 22 bits to share between SnowFlakeNode/Step
	StepBits uint8 = 12
)
View Source
var ErrInvalidBase32 = errors.New("invalid base32")

ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte

View Source
var ErrInvalidBase58 = errors.New("invalid base58")

ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte

Functions

func AesDecrypt

func AesDecrypt(data []byte, key []byte) ([]byte, error)

AesDecrypt Decrypt

func AesEncrypt

func AesEncrypt(data []byte, key []byte) ([]byte, error)

AesEncrypt Encrypt

func CopyFile added in v1.3.109

func CopyFile(srcFile, dstFile string, delSource bool) (err error)

func CryptoByMd5

func CryptoByMd5(data []byte, saltVal []byte) []byte

func DecryptByAes

func DecryptByAes(data, pwdKey string) (string, error)

DecryptByAes Decrypt using AES

func EncryptByAes

func EncryptByAes(data, pwdKey string) (string, error)

EncryptByAes Encrypt using AES and then base64 encode

func ExistIntArray

func ExistIntArray(val int, array []int) bool

ExistIntArray 是否存在数组中

func ExtractSummary

func ExtractSummary(content string) string

ExtractSummary 抽取摘要

func ExtractTelephone

func ExtractTelephone(val string) (ret string)

func GenerateKey added in v1.3.109

func GenerateKey(pwdKey []byte) []byte

GenerateKey Generates a secure key using SHA-256

func GetCurrentWorkDir added in v1.4.0

func GetCurrentWorkDir() string

func GetDefaultShell added in v1.4.0

func GetDefaultShell() string

func GetOsName added in v1.4.0

func GetOsName() string

func GetStack added in v1.3.49

func GetStack(skip int) []byte

func IntArray2Str

func IntArray2Str(ids []int) string

IntArray2Str 将整数数组转换为逗号分隔的字符串

func LoadConfig

func LoadConfig(filePath string, ptr interface{}) (err error)

func MarshalString

func MarshalString(val interface{}) string

MarshalString 将任意类型的值转换为 JSON 字符串

func NewUUID added in v1.3.4

func NewUUID() string

func RandomAlphaOrNumeric

func RandomAlphaOrNumeric(count uint, letters, numbers bool) string

RandomAlphaOrNumeric 创建一个指定长度的随机字符串。 字符将从参数指示的字母数字字符集中选择。

func RandomAlphabetic

func RandomAlphabetic(count uint) string

RandomAlphabetic 创建一个指定长度的随机字符串。 字符将从字母字符集中选择。

func RandomAlphanumeric

func RandomAlphanumeric(count uint) string

RandomAlphanumeric 创建一个指定长度的随机字符串。 字符将从字母数字字符集中选择。

func RandomAscII

func RandomAscII(count uint) string

RandomAscII 创建一个指定长度的随机字符串。 字符将从 ASCII 值在 32 到 126(包括)之间的字符集中选择。

func RandomIdentifyCode

func RandomIdentifyCode() string

RandomIdentifyCode 生成6位随机数验证码

func RandomNumeric

func RandomNumeric(count uint) string

RandomNumeric 创建一个指定长度的随机字符串。 字符将从数字字符集中选择。

func RandomSpec0

func RandomSpec0(count uint, start, end int, letters, numbers bool,
	chars []rune, rand *rand.Rand) string

RandomSpec0 根据各种选项创建随机字符串,使用提供的随机源。 如果 start 和 end 都为0,则 start 和 end 被设置为 ' ' 和 'z',即 ASCII 可打印字符。 如果 letters 和 numbers 都为 false,则 start 和 end 被设置为 0 和 math.MaxInt32。 如果 set 不为 nil,则从 start 和 end 之间的字符中选择。 该方法接受一个用户提供的 rand.Rand 实例作为随机源。

func RandomSpec1

func RandomSpec1(count uint, start, end int, letters, numbers bool) string

RandomSpec1 创建一个指定长度的随机字符串。 字符将从参数指示的字母数字字符集中选择。

func RandomString

func RandomString(count uint) string

RandomString 创建一个指定长度的随机字符串。

func RandomStringSpec0

func RandomStringSpec0(count uint, set []rune) string

RandomStringSpec0 创建一个指定长度的随机字符串。

func RandomStringSpec1

func RandomStringSpec1(count uint, set string) string

RandomStringSpec1 创建一个指定长度的随机字符串。

func SameIntArray

func SameIntArray(val []int, array []int) bool

SameIntArray 是否存在数组中

func SaveConfig

func SaveConfig(filePath string, ptr interface{}) (err error)

func Str2IntArray

func Str2IntArray(str string) ([]int, bool)

Str2IntArray 将逗号分隔的字符串转换为整数数组

func UnZipFile added in v1.4.0

func UnZipFile(zipFile, destDir string) (ret []string, err error)

func UnmarshalString

func UnmarshalString(val string) interface{}

UnmarshalString 将 JSON 字符串解析为相应的 Go 类型

func ValidateFunc

func ValidateFunc(fun interface{})

ValidateFunc 校验是否是函数

func ValidatePtr

func ValidatePtr(ptr interface{})

ValidatePtr 校验是否是指针

func ZipDir added in v1.4.0

func ZipDir(sourceDir, outputFile string) error

func ZipFile added in v1.4.0

func ZipFile(file, outputFile string) (err error)

func ZipFiles added in v1.4.0

func ZipFiles(files []string, outputFile string) error

Types

type Filter

type Filter interface {
	Filter(val interface{}) bool
}

Filter value filter

type ID added in v1.3.4

type ID int64

An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.

func ParseBase2 added in v1.3.4

func ParseBase2(id string) (ID, error)

ParseBase2 converts a Base2 string into a snowflake ID

func ParseBase32 added in v1.3.4

func ParseBase32(b []byte) (ID, error)

ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func ParseBase36 added in v1.3.4

func ParseBase36(id string) (ID, error)

ParseBase36 converts a Base36 string into a snowflake ID

func ParseBase58 added in v1.3.4

func ParseBase58(b []byte) (ID, error)

ParseBase58 parses a base58 []byte into a snowflake ID

func ParseBase64 added in v1.3.4

func ParseBase64(id string) (ID, error)

ParseBase64 converts a base64 string into a snowflake ID

func ParseBytes added in v1.3.4

func ParseBytes(id []byte) (ID, error)

ParseBytes converts a byte slice into a snowflake ID

func ParseInt64 added in v1.3.4

func ParseInt64(id int64) ID

ParseInt64 converts an int64 into a snowflake ID

func ParseIntBytes added in v1.3.4

func ParseIntBytes(id [8]byte) ID

ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake ID

func ParseString added in v1.3.4

func ParseString(id string) (ID, error)

ParseString converts a string into a snowflake ID

func (ID) Base2 added in v1.3.4

func (f ID) Base2() string

Base2 returns a string base2 of the snowflake ID

func (ID) Base32 added in v1.3.4

func (f ID) Base32() string

Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func (ID) Base36 added in v1.3.4

func (f ID) Base36() string

Base36 returns a base36 string of the snowflake ID

func (ID) Base58 added in v1.3.4

func (f ID) Base58() string

Base58 returns a base58 string of the snowflake ID

func (ID) Base64 added in v1.3.4

func (f ID) Base64() string

Base64 returns a base64 string of the snowflake ID

func (ID) Bytes added in v1.3.4

func (f ID) Bytes() []byte

Bytes returns a byte slice of the snowflake ID

func (ID) Int64 added in v1.3.4

func (f ID) Int64() int64

Int64 returns an int64 of the snowflake ID

func (ID) IntBytes added in v1.3.4

func (f ID) IntBytes() [8]byte

IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.

func (ID) MarshalJSON added in v1.3.4

func (f ID) MarshalJSON() ([]byte, error)

MarshalJSON returns a json byte array string of the snowflake ID.

func (ID) Node added in v1.3.4

func (f ID) Node() int64

SnowFlakeNode returns an int64 of the snowflake ID node number DEPRECATED: the below function will be removed in a future release.

func (ID) Step added in v1.3.4

func (f ID) Step() int64

Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.

func (ID) String added in v1.3.4

func (f ID) String() string

String returns a string of the snowflake ID

func (ID) Time added in v1.3.4

func (f ID) Time() int64

Time returns an int64 unix timestamp in milliseconds of the snowflake ID time DEPRECATED: the below function will be removed in a future release.

func (*ID) UnmarshalJSON added in v1.3.4

func (f *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.

type JSONSyntaxError added in v1.3.4

type JSONSyntaxError struct {
	// contains filtered or unexported fields
}

A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.

func (JSONSyntaxError) Error added in v1.3.4

func (j JSONSyntaxError) Error() string

type ObjectSorter

type ObjectSorter interface {
	Less(left, right interface{}) bool
}

ObjectSorter help object slice sort

type SnowFlakeNode added in v1.3.4

type SnowFlakeNode struct {
	// contains filtered or unexported fields
}

A SnowFlakeNode struct holds the basic information needed for a snowflake generator node

func NewSnowFlakeNode added in v1.3.4

func NewSnowFlakeNode(node int64) (*SnowFlakeNode, error)

NewSnowFlakeNode returns a new snowflake node that can be used to generate snowflake IDs

func (*SnowFlakeNode) Generate added in v1.3.4

func (n *SnowFlakeNode) Generate() ID

Generate creates and returns a unique snowflake ID To help guarantee uniqueness - Make sure your system is keeping accurate system time - Make sure you never have multiple nodes running with the same node ID

type SortFilter

type SortFilter struct {
	// true:升序,false:降序
	AscFlag bool `json:"ascFlag"`
	// 排序字段
	FieldName string `json:"fieldName"`
}

SortFilter 页面过滤器

func NewSortFilter

func NewSortFilter(name string, ascFlag bool) *SortFilter

func (*SortFilter) AscSort

func (s *SortFilter) AscSort() bool

func (*SortFilter) Name

func (s *SortFilter) Name() string

Name return name

func (*SortFilter) String added in v1.4.0

func (s *SortFilter) String() string

type SortHelper

type SortHelper struct {
	// contains filtered or unexported fields
}

SortHelper sortHelper

func NewSortHelper

func NewSortHelper(objList []interface{}, sorter ObjectSorter) *SortHelper

NewSortHelper new SortHelper

func (SortHelper) Len

func (s SortHelper) Len() int

func (SortHelper) Less

func (s SortHelper) Less(i, j int) bool

func (SortHelper) Swap

func (s SortHelper) Swap(i, j int)

type StringSet

type StringSet []string

func (StringSet) Add

func (s StringSet) Add(val string) StringSet

func (StringSet) Empty

func (s StringSet) Empty() bool

func (StringSet) Exist added in v1.4.0

func (s StringSet) Exist(val string) bool

func (StringSet) Remove

func (s StringSet) Remove(val string) StringSet

type StringSortSet added in v1.4.1

type StringSortSet []string

有序字符串集

func (StringSortSet) Add added in v1.4.1

func (s StringSortSet) Add(val string) StringSortSet

func (StringSortSet) Exist added in v1.4.1

func (s StringSortSet) Exist(val string) bool

func (StringSortSet) Len added in v1.4.1

func (s StringSortSet) Len() int

func (StringSortSet) Range added in v1.4.1

func (s StringSortSet) Range(f func(string) bool)

func (StringSortSet) Remove added in v1.4.1

func (s StringSortSet) Remove(val string) StringSortSet

type Validator

type Validator interface {
	Validate(value interface{}) error
}

func NewFormValidator

func NewFormValidator() Validator

Jump to

Keyboard shortcuts

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