Documentation
¶
Index ¶
- Constants
- Variables
- func AbsPath(relativePath string) (string, error)
- func AddQueryParam(url, key, value string) string
- func AddQueryParamFlag(url, key string) string
- func AddQueryParamInt(url, key string, value int) string
- func AnyArrayContainsIgnoreCase(s []string, strs ...string) bool
- func AnyContainsIgnoreCase(s string, strs ...string) bool
- func ArrayIntContains(arr []int, str int) bool
- func BoolToString(b bool) string
- func CRC(len int, key string) string
- func CalculateMD5(data []byte) (string, error)
- func CalculateMD5WithChunkSize(data []byte, chunkSize int) (string, error)
- func CommonCharCount(text1, text2 string) int
- func CommonCharSimilarity(text1, text2 string) int
- func ContainsAny(s string, strs ...string) bool
- func ContainsAnyIgnoreCase(s string, strs ...string) bool
- func ContainsAnyIgnorePunctuation(s string, strs ...string) bool
- func CreateDirIfNoExists(path string) error
- func CreateFileIfNoExists(path string) error
- func DaysBetween(t1 time.Time, t2 time.Time) int
- func DecodeBase64URL(encoded string) (string, error)
- func DecodeFileBase64(base64Str string) ([]byte, error)
- func DecryptByCBC(cipherText string, key string, iv string) (string, error)
- func DecryptCBCBase64(key, iv []byte, cipherTextBase64 string) ([]byte, error)
- func DecryptCBCBytes(key, iv, ciphertext []byte) ([]byte, error)
- func DeduplicateIds(ids string) string
- func EncryptByCBC(text string, key string, iv string) (string, error)
- func EqualsAnyIgnoreCase(s string, strs ...string) bool
- func EqualsAnyIgnorePunctuation(s string, strs ...string) bool
- func EqualsAnyIgnorePunctuationAndCase(s string, strs ...string) bool
- func ExecDir() (string, error)
- func ExistsFile(path string) bool
- func ExtractEmails(text string) []string
- func FormatDate(tm time.Time) string
- func FormatMail(name, mail string) string
- func FormatTime(tm time.Time) string
- func GenerateRandomNum(length int) string
- func GenerateRandomString(length int, charset string) string
- func GenerateRandomStringByAlphanumeric(length int) string
- func GetCachePath(rootPath, filename string) string
- func GetDomainFromHost(host string) string
- func GetDomainFromURL(rawURL string) string
- func GetEnv(key string) string
- func GetEnvBool(key string) bool
- func GetEnvBoolOrDefault(key string, defaultValue bool) bool
- func GetEnvInt(key string) int
- func GetEnvIntOrDefault(key string, defaultValue int) int
- func GetEnvOrDefault(key, defaultValue string) string
- func GetHost(rawURL string) string
- func GetMap(key string, value any) map[string]any
- func GetNowTime() time.Time
- func GetStructFullName(v any) string
- func GetStructFullQualifiedName(v any) string
- func GetStructName(v any) string
- func GetStructPkgPath(v any) string
- func HidePhone(phone string) string
- func Index2Str(index int, charset string) string
- func IsAfter(pre string, now time.Time, timestampFormat string) (bool, error)
- func IsAfterTime(pre string, now time.Time) (bool, error)
- func IsBlank(str string) bool
- func IsDomain(str string) bool
- func IsImagePath(path string) bool
- func IsMatch(value, regx string) bool
- func IsMatchPath(path, smath string) bool
- func IsNotBlank(str string) bool
- func IsNumber(value string) bool
- func JoinUrl(root string, args ...string) string
- func JoinValues(values ...any) string
- func JsonEncode(v any) (string, error)
- func MD5(data []byte) string
- func MD5Str(data string) string
- func Millisecond() uint32
- func NewPtr[T any](v T) T
- func NewSlice[T any](v T) []T
- func NowDateFormatTime(timestampFormat string) string
- func NowDateTime() string
- func Number2String(number int64, charset string) string
- func OfMap(key string, value any) map[string]any
- func OfMap2(key string, value any, key2 string, value2 any) map[string]any
- func PKCS7Pad(data []byte, blockSize int) []byte
- func PKCS7Unpad(data []byte) ([]byte, error)
- func ParseFormatTime(timeStr, timestampFormat string) (time.Time, error)
- func ParseMail(recipient string) (name string, mail string, err error)
- func ParseTemplate(templateStr string, data map[string]interface{}) (string, error)
- func ReadFile(path string) (string, error)
- func ReadFileBytes(path string) ([]byte, error)
- func RemoveDuplicates(nums []string) []string
- func RemovePunctuation(s string) string
- func ReplaceAllRegex(path, regex, math string) string
- func SHA1(str string) string
- func SHA1Bytes(data []byte) string
- func Second() int64
- func Second2Base62() string
- func SplitAndDeduplicate(text, sep string) []string
- func SplitPath(path string) []string
- func StartsWithAny(s string, prefix ...string) bool
- func StartsWithAnyIgnoreCase(s string, prefix ...string) bool
- func String2Number(s string, charset string) int64
- func StringToBool(s string) bool
- func StringToInt(s string) int
- func StringToUInt(s string) uint
- func StringToUintIds(ids string) []uint
- func SubStringAndPadSpace(value string, length int) string
- func SubStringLastMaxLength(value string, maxLength int) string
- func SubStringMaxLength(value string, maxLength int) string
- func TextSimilarity(text1, text2 string) int
- func Trim(value string) string
- func WriteBase64File(base64Str string, dst string) error
- func WriteBytesFile(file *os.File, dataS ...[]byte) error
- func WriteBytesFilePath(path string, dataS ...[]byte) error
- func WriteFile(bytes []byte, dst string) error
- type Configure
- type File
- func (f *File) Abs() string
- func (f *File) Child(path string) (*File, error)
- func (f *File) Close() error
- func (f *File) Exists() (flag bool, err error)
- func (f *File) IsDir() bool
- func (f *File) IsDisk() bool
- func (f *File) List() ([]*File, error)
- func (f *File) MkDirs() error
- func (f *File) ModTime() (*time.Time, error)
- func (f *File) Name() string
- func (f *File) OpenAppendOrCreate() error
- func (f *File) OpenAppendWrite() (*bufio.Writer, error)
- func (f *File) OpenOrCreate() error
- func (f *File) OpenWrite() (*bufio.Writer, error)
- func (f *File) Parent() string
- func (f *File) ParentFile() (*File, error)
- func (f *File) ReadAll() ([]byte, error)
- func (f *File) ReadBytes(p []byte) (n int, err error)
- func (f *File) ToRawFile() (*os.File, error)
- func (f *File) Truncate() error
- func (f *File) WriteAppendBytes(data []byte) error
- func (f *File) WriteBytes(data []byte) error
- type Page
- type PageAble
Constants ¶
const ( // Alphanumeric 包含大小写字母和数字 Alphanumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // Lowercase 仅包含小写字母 Lowercase = "abcdefghijklmnopqrstuvwxyz" // Uppercase 仅包含大写字母 Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // Numeric 仅包含数字 Numeric = "0123456789" // WithSpecialChars 包含字母、数字和常见特殊字符 WithSpecialChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()" )
预设字符集
const DefaultChunkSize = 4096 // 4KB
DefaultChunkSize 常用分块大小:4KB,与大多数操作系统页大小一致
const DefaultPageNo = 1
const DefaultPageSize = 10
Variables ¶
var DateFormat = "2006-01-02"
var TimestampFormat = "2006-01-02 15:04:05"
Functions ¶
func AddQueryParam ¶ added in v0.6.1
AddQueryParam adds a query parameter to a URL string. It automatically detects whether the URL already has query parameters and uses the appropriate separator (? or &).
Example:
AddQueryParam("/path", "key", "value") -> "/path?key=value"
AddQueryParam("/path?foo=bar", "key", "value") -> "/path?foo=bar&key=value"
func AddQueryParamFlag ¶ added in v0.6.1
AddQueryParamFlag adds a boolean flag query parameter (key=1) to a URL string.
func AddQueryParamInt ¶ added in v0.6.1
AddQueryParamInt adds an integer query parameter to a URL string.
func AnyArrayContainsIgnoreCase ¶ added in v0.1.2
AnyArrayContainsIgnoreCase 检查目标字符串切片 s 中是否存在任意一个字符串,忽略大小写地包含任意一个待匹配字符串 strs 参数 s: 源字符串切片 参数 strs: 可变参数,待匹配的一个或多个子字符串 返回值: 只要 s 中有一个字符串包含任意一个 strs 中的子字符串(忽略大小写),返回 true;否则返回 false
func AnyContainsIgnoreCase ¶ added in v0.1.2
func ArrayIntContains ¶ added in v0.1.1
func BoolToString ¶
func CalculateMD5 ¶
CalculateMD5 计算字节数组的MD5哈希值(自动分块处理)
func CalculateMD5WithChunkSize ¶
CalculateMD5WithChunkSize 支持自定义分块大小的MD5计算 适合处理超大字节数组,避免一次性加载全部数据
func CommonCharCount ¶ added in v0.9.1
CommonCharCount 计算两个文本中相同字符的数量(每个字符只计一次,去重计数) 返回值是相同独立字符的个数
func CommonCharSimilarity ¶ added in v0.9.1
CommonCharSimilarity 基于 CommonCharCount 计算相似度(0-100) 得分 = 相同去重字符数 / max(len(text1), len(text2)) * 100
func ContainsAny ¶
func ContainsAnyIgnoreCase ¶
func ContainsAnyIgnorePunctuation ¶ added in v0.7.1
func CreateDirIfNoExists ¶ added in v0.0.2
func CreateFileIfNoExists ¶ added in v0.1.2
func DecodeBase64URL ¶ added in v0.6.1
DecodeBase64URL 解码 base64 URL 编码的字符串(自动处理 padding)
func DecodeFileBase64 ¶
DecodeBase64 解码base64字符串为字节数组
func DecryptByCBC ¶
DecryptByCBC AES-256-CBC 解密实现
func DecryptCBCBase64 ¶ added in v0.6.1
DecryptCBCBase64 AES-256-CBC 解密(Base64密文版本) key: 32字节密钥 iv: 16字节IV(如果为nil则使用key的前16字节) cipherTextBase64: Base64编码的密文 返回:解密后的明文
func DecryptCBCBytes ¶ added in v0.6.1
DecryptCBCBytes AES-256-CBC 解密(字节数组版本) key: 32字节密钥 iv: 16字节IV(如果为nil则使用key的前16字节) ciphertext: 密文 返回:解密后的明文
func DeduplicateIds ¶
func EncryptByCBC ¶
EncryptByCBC AES-256-CBC 加密实现
func EqualsAnyIgnoreCase ¶
func EqualsAnyIgnorePunctuation ¶ added in v0.6.1
EqualsAnyIgnorePunctuation 比较字符串是否相等(忽略标点符号)
func EqualsAnyIgnorePunctuationAndCase ¶ added in v0.6.1
EqualsAnyIgnorePunctuationAndCase 比较字符串是否相等(忽略标点符号和大小写)
func ExistsFile ¶ added in v0.0.2
ExistsFile 判断指定路径是否为**存在的文件**(非目录、非不存在) 返回值:true=文件存在;false=文件不存在/是目录/其他错误
func ExtractEmails ¶ added in v0.1.2
func FormatDate ¶
func FormatMail ¶ added in v0.1.2
func FormatTime ¶
func GenerateRandomNum ¶
func GenerateRandomString ¶
GenerateRandomString 生成指定长度的随机字符串 length: 字符串长度 charset: 字符集,如果为空则使用默认的字母数字字符集
func GetCachePath ¶
func GetDomainFromHost ¶
func GetDomainFromURL ¶
func GetEnvBool ¶ added in v0.1.2
func GetEnvBoolOrDefault ¶ added in v0.1.2
func GetEnvIntOrDefault ¶ added in v0.1.2
func GetEnvOrDefault ¶ added in v0.1.2
func GetNowTime ¶
func GetStructFullName ¶ added in v0.1.2
func GetStructFullQualifiedName ¶ added in v0.5.1
GetStructFullQualifiedName returns the fully qualified name of the struct including full package path (e.g. "github.com/chuccp/antilost_qrcode_go/rest.User")
func GetStructName ¶ added in v0.1.2
func GetStructPkgPath ¶ added in v0.5.1
GetStructPkgPath returns the full package path of the struct (e.g. "github.com/chuccp/antilost_qrcode_go/rest")
func IsImagePath ¶ added in v0.1.2
IsImageByURL 通过URL路径判断是否为图片 参数:rawURL 原始URL字符串(如"https://example.com/photo.jpg?width=100") 返回:bool(是否为图片)、error(URL解析错误)
func IsMatchPath ¶
func IsNotBlank ¶
func JoinUrl ¶ added in v0.6.1
JoinUrl joins URL path segments into a single URL string. It properly handles leading and trailing slashes between segments. It also normalizes backslashes to forward slashes (useful for Windows paths).
Example:
JoinUrl("http://example.com", "api", "users") -> "http://example.com/api/users"
JoinUrl("/api", "users", "1") -> "/api/users/1"
JoinUrl("http://example.com/", "/api/", "/users/") -> "http://example.com/api/users"
JoinUrl("C:\\static\\voice", "58\\file.mp3") -> "C:/static/voice/58/file.mp3"
func JoinValues ¶ added in v0.0.4
func JsonEncode ¶ added in v0.1.2
func Millisecond ¶
func Millisecond() uint32
func NowDateFormatTime ¶ added in v0.1.2
func NowDateTime ¶
func NowDateTime() string
func Number2String ¶
func PKCS7Unpad ¶ added in v0.6.1
PKCS7Unpad 去除 PKCS7 填充
func ParseFormatTime ¶ added in v0.1.2
func ParseTemplate ¶ added in v0.1.1
func ReadFileBytes ¶
func RemoveDuplicates ¶
func RemovePunctuation ¶ added in v0.6.1
RemovePunctuation 移除字符串中的标点符号和特殊符号(保留中文、英文、数字)
func ReplaceAllRegex ¶
func Second2Base62 ¶
func Second2Base62() string
func SplitAndDeduplicate ¶
func StartsWithAny ¶ added in v0.2.1
func StartsWithAnyIgnoreCase ¶ added in v0.0.4
func String2Number ¶ added in v0.9.3
String2Number 将指定字符集编码的字符串解码为数字,是 Number2String 的逆操作
func StringToBool ¶
func StringToInt ¶
func StringToUInt ¶
func StringToUintIds ¶
func SubStringAndPadSpace ¶ added in v0.1.2
SubStringAndPadSpace 截取字符串到指定长度,若原字符串长度不足则右侧补空格 参数:
value - 原始字符串 length - 目标字符串长度
返回值:
截取/填充后的指定长度字符串
func SubStringLastMaxLength ¶ added in v0.1.3
func SubStringMaxLength ¶ added in v0.1.3
func TextSimilarity ¶ added in v0.7.1
TextSimilarity 计算两个文本的相似度得分(0-100) 使用基于公共子串的相似度算法
func WriteBase64File ¶
func WriteBytesFilePath ¶ added in v0.0.2
Types ¶
type File ¶ added in v0.0.2
type File struct {
// contains filtered or unexported fields
}
func GetRootPath ¶ added in v0.0.2
func (*File) OpenAppendOrCreate ¶ added in v0.0.2
func (*File) OpenAppendWrite ¶ added in v0.0.2
func (*File) OpenOrCreate ¶ added in v0.0.2
func (*File) ParentFile ¶ added in v0.0.2
func (*File) WriteAppendBytes ¶ added in v0.0.2
func (*File) WriteBytes ¶ added in v0.0.2
type Page ¶ added in v1.0.4
type Page struct {
PageNo int // Current page number, 1-based
PageSize int // Number of items per page
LastId int // Last seen ID for cursor-based pagination
}
Page represents pagination parameters for list queries.