util

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Alphanumeric 包含大小写字母和数字
	Alphanumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	// Lowercase 仅包含小写字母
	Lowercase = "abcdefghijklmnopqrstuvwxyz"
	// Uppercase 仅包含大写字母
	Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	// Numeric 仅包含数字
	Numeric = "0123456789"
	// WithSpecialChars 包含字母、数字和常见特殊字符
	WithSpecialChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()"
)

预设字符集

View Source
const DefaultChunkSize = 4096 // 4KB

DefaultChunkSize 常用分块大小:4KB,与大多数操作系统页大小一致

Variables

View Source
var DateFormat = "2006-01-02"
View Source
var TimestampFormat = "2006-01-02 15:04:05"

Functions

func AnyArrayContainsIgnoreCase added in v0.1.2

func AnyArrayContainsIgnoreCase(s []string, strs ...string) bool

AnyArrayContainsIgnoreCase 检查目标字符串切片 s 中是否存在任意一个字符串,忽略大小写地包含任意一个待匹配字符串 strs 参数 s: 源字符串切片 参数 strs: 可变参数,待匹配的一个或多个子字符串 返回值: 只要 s 中有一个字符串包含任意一个 strs 中的子字符串(忽略大小写),返回 true;否则返回 false

func AnyContainsIgnoreCase added in v0.1.2

func AnyContainsIgnoreCase(s string, strs ...string) bool

func ArrayIntContains added in v0.1.1

func ArrayIntContains(arr []int, str int) bool

func BoolToString

func BoolToString(b bool) string

func CRC added in v0.1.2

func CRC(len int, key string) string

func CalculateMD5

func CalculateMD5(data []byte) (string, error)

CalculateMD5 计算字节数组的MD5哈希值(自动分块处理)

func CalculateMD5WithChunkSize

func CalculateMD5WithChunkSize(data []byte, chunkSize int) (string, error)

CalculateMD5WithChunkSize 支持自定义分块大小的MD5计算 适合处理超大字节数组,避免一次性加载全部数据

func ContainsAny

func ContainsAny(s string, strs ...string) bool

func ContainsAnyIgnoreCase

func ContainsAnyIgnoreCase(s string, strs ...string) bool

func CreateDirIfNoExists added in v0.0.2

func CreateDirIfNoExists(path string) error

func CreateFileIfNoExists added in v0.1.2

func CreateFileIfNoExists(path string) error

func DecodeFileBase64

func DecodeFileBase64(base64Str string) ([]byte, error)

DecodeBase64 解码base64字符串为字节数组

func DecryptByCBC

func DecryptByCBC(cipherText string, key string, iv string) (string, error)

DecryptByCBC AES-256-CBC 解密实现

func DeduplicateIds

func DeduplicateIds(ids string) string

func EncryptByCBC

func EncryptByCBC(text string, key string, iv string) (string, error)

EncryptByCBC AES-256-CBC 加密实现

func EqualsAnyIgnoreCase

func EqualsAnyIgnoreCase(s string, strs ...string) bool

func ExistsFile added in v0.0.2

func ExistsFile(path string) bool

ExistsFile 判断指定路径是否为**存在的文件**(非目录、非不存在) 返回值:true=文件存在;false=文件不存在/是目录/其他错误

func ExtractEmails added in v0.1.2

func ExtractEmails(text string) []string

func FormatDate

func FormatDate(tm time.Time) string

func FormatMail added in v0.1.2

func FormatMail(name, mail string) string

func FormatTime

func FormatTime(tm time.Time) string

func GenerateQrcode

func GenerateQrcode(content string, writeCloser io.WriteCloser, opts ...standard.ImageOption) error

func GenerateRandomNum

func GenerateRandomNum(length int) string

func GenerateRandomString

func GenerateRandomString(length int, charset string) string

GenerateRandomString 生成指定长度的随机字符串 length: 字符串长度 charset: 字符集,如果为空则使用默认的字母数字字符集

func GenerateRandomStringByAlphanumeric

func GenerateRandomStringByAlphanumeric(length int) string

func GetCachePath

func GetCachePath(rootPath, filename string) string

func GetDomainFromHost

func GetDomainFromHost(host string) string

func GetDomainFromURL

func GetDomainFromURL(rawURL string) string

func GetEnv added in v0.1.2

func GetEnv(key string) string

func GetEnvBool added in v0.1.2

func GetEnvBool(key string) bool

func GetEnvBoolOrDefault added in v0.1.2

func GetEnvBoolOrDefault(key string, defaultValue bool) bool

func GetEnvInt added in v0.1.2

func GetEnvInt(key string) int

func GetEnvIntOrDefault added in v0.1.2

func GetEnvIntOrDefault(key string, defaultValue int) int

func GetEnvOrDefault added in v0.1.2

func GetEnvOrDefault(key, defaultValue string) string

func GetHost

func GetHost(rawURL string) string

func GetMap

func GetMap(key string, value any) map[string]any

func GetNowTime

func GetNowTime() time.Time

func GetStructFullName added in v0.1.2

func GetStructFullName(v any) string

func GetStructName added in v0.1.2

func GetStructName(v any) string

func HidePhone added in v0.1.2

func HidePhone(phone string) string

func Index2Str

func Index2Str(index int, charset string) string

func IsAfter added in v0.1.2

func IsAfter(pre string, now time.Time, timestampFormat string) bool

func IsBlank

func IsBlank(str string) bool

func IsDomain added in v0.1.1

func IsDomain(str string) bool

func IsImagePath added in v0.1.2

func IsImagePath(path string) bool

IsImageByURL 通过URL路径判断是否为图片 参数:rawURL 原始URL字符串(如"https://example.com/photo.jpg?width=100") 返回:bool(是否为图片)、error(URL解析错误)

func IsMatch

func IsMatch(value, regx string) bool

func IsMatchPath

func IsMatchPath(path, smath string) bool

func IsNotBlank

func IsNotBlank(str string) bool

func IsNumber

func IsNumber(value string) bool

func IsWhite added in v0.1.1

func IsWhite(c color.Color) bool

func JoinValues added in v0.0.4

func JoinValues(values ...any) string

func JsonEncode added in v0.1.2

func JsonEncode(v any) (string, error)

func MD5

func MD5(data []byte) string

func MD5Str

func MD5Str(data string) string

func Millisecond

func Millisecond() uint32

func NewPtr

func NewPtr[T any](v T) T

func NewSlice

func NewSlice[T any](v T) []T

func NowDateFormatTime added in v0.1.2

func NowDateFormatTime(timestampFormat string) string

func NowDateTime

func NowDateTime() string

func Number2String

func Number2String(number int64, charset string) string

func OfMap

func OfMap(key string, value any) map[string]any

func OfMap2 added in v0.1.2

func OfMap2(key string, value any, key2 string, value2 any) map[string]any

func ParseFormatTime added in v0.1.2

func ParseFormatTime(timeStr, timestampFormat string) (time.Time, error)

func ParseMail added in v0.1.2

func ParseMail(recipient string) (name string, mail string, err error)

func ParseTemplate added in v0.1.1

func ParseTemplate(templateStr string, data map[string]interface{}) (string, error)

func ReadFile

func ReadFile(path string) (string, error)

func ReadFileBytes

func ReadFileBytes(path string) ([]byte, error)

func RemoveDuplicates

func RemoveDuplicates(nums []string) []string

func ReplaceAllRegex

func ReplaceAllRegex(path, regex, math string) string

func Second

func Second() int64

func Second2Base62

func Second2Base62() string

func SplitAndDeduplicate

func SplitAndDeduplicate(text, sep string) []string

func SplitPath

func SplitPath(path string) []string

func StartsWithAnyIgnoreCase added in v0.0.4

func StartsWithAnyIgnoreCase(s string, prefix ...string) bool

func StringToBool

func StringToBool(s string) bool

func StringToInt

func StringToInt(s string) int

func StringToUInt

func StringToUInt(s string) uint

func StringToUintIds

func StringToUintIds(ids string) []uint

func SubStringAndPadSpace added in v0.1.2

func SubStringAndPadSpace(value string, length int) string

SubStringAndPadSpace 截取字符串到指定长度,若原字符串长度不足则右侧补空格 参数:

value - 原始字符串
length - 目标字符串长度

返回值:

截取/填充后的指定长度字符串

func Trim

func Trim(value string) string

func WithRoundedSquareShape

func WithRoundedSquareShape() standard.ImageOption

func WriteBase64File

func WriteBase64File(base64Str string, dst string) error

func WriteBytesFile added in v0.0.2

func WriteBytesFile(file *os.File, dataS ...[]byte) error

func WriteBytesFilePath added in v0.0.2

func WriteBytesFilePath(path string, dataS ...[]byte) error

func WriteFile

func WriteFile(bytes []byte, dst string) error

Types

type BufferWriteCloser added in v0.0.3

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

func CreateBufferWriteCloser added in v0.0.3

func CreateBufferWriteCloser() *BufferWriteCloser

func (*BufferWriteCloser) Bytes added in v0.0.3

func (w *BufferWriteCloser) Bytes() []byte

func (*BufferWriteCloser) Close added in v0.0.3

func (w *BufferWriteCloser) Close() error

func (*BufferWriteCloser) Write added in v0.0.3

func (w *BufferWriteCloser) Write(p []byte) (n int, err error)

type Configure

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

type File added in v0.0.2

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

func GetRootPath added in v0.0.2

func GetRootPath() ([]*File, error)

func NewFile added in v0.0.2

func NewFile(path string) (*File, error)

func (*File) Abs added in v0.0.2

func (f *File) Abs() string

func (*File) Child added in v0.0.2

func (f *File) Child(path string) (*File, error)

func (*File) Close added in v0.0.2

func (f *File) Close() error

func (*File) Exists added in v0.0.2

func (f *File) Exists() (flag bool, err error)

func (*File) IsDir added in v0.0.2

func (f *File) IsDir() bool

func (*File) IsDisk added in v0.0.2

func (f *File) IsDisk() bool

func (*File) List added in v0.0.2

func (f *File) List() ([]*File, error)

func (*File) MkDirs added in v0.0.2

func (f *File) MkDirs() error

func (*File) ModTime added in v0.0.2

func (f *File) ModTime() (*time.Time, error)

func (*File) Name added in v0.0.2

func (f *File) Name() string

func (*File) OpenAppendOrCreate added in v0.0.2

func (f *File) OpenAppendOrCreate() error

func (*File) OpenAppendWrite added in v0.0.2

func (f *File) OpenAppendWrite() (*bufio.Writer, error)

func (*File) OpenOrCreate added in v0.0.2

func (f *File) OpenOrCreate() error

func (*File) OpenWrite added in v0.0.2

func (f *File) OpenWrite() (*bufio.Writer, error)

func (*File) Parent added in v0.0.2

func (f *File) Parent() string

func (*File) ParentFile added in v0.0.2

func (f *File) ParentFile() (*File, error)

func (*File) ReadAll added in v0.0.2

func (f *File) ReadAll() ([]byte, error)

func (*File) ReadBytes added in v0.0.2

func (f *File) ReadBytes(p []byte) (n int, err error)

func (*File) ToRawFile added in v0.0.2

func (f *File) ToRawFile() (*os.File, error)

func (*File) Truncate added in v0.0.2

func (f *File) Truncate() error

func (*File) WriteAppendBytes added in v0.0.2

func (f *File) WriteAppendBytes(data []byte) error

func (*File) WriteBytes added in v0.0.2

func (f *File) WriteBytes(data []byte) error

type ShapeRoundedSquare

type ShapeRoundedSquare struct {
	Color color.Color
}

func (*ShapeRoundedSquare) Draw

func (s *ShapeRoundedSquare) Draw(ctx *standard.DrawContext)

func (*ShapeRoundedSquare) DrawFinder

func (s *ShapeRoundedSquare) DrawFinder(ctx *standard.DrawContext)

Jump to

Keyboard shortcuts

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