Documentation
¶
Index ¶
- func AESDecrypt(cipherText []byte, key []byte) ([]byte, error)
- func AESEncrypt(plainText []byte, key []byte) ([]byte, error)
- func AppendToFile(filePath, content string) error
- func Base64Decode(encoded string) ([]byte, error)
- func Base64Encode(data []byte) string
- func Base64UrlDecode(encoded string) ([]byte, error)
- func Base64UrlEncode(data []byte) string
- func BatchProcess[T any](items []T, batchSize int, maxGoroutines int, ...) error
- func BytesToImage(data []byte) (image.Image, error)
- func Capitalize(s string) string
- func CenterAlign(s string, width int, padChar rune) string
- func CheckPasswordHash(password, hash string) bool
- func ContainsAll(s string, subs ...string) bool
- func ContainsAny(s string, subs ...string) bool
- func CopyFile(src, dst string) error
- func CountLines(s string) int
- func CountSubstring(s, sub string) int
- func CountWords(s string) int
- func CreateDir(dirPath string) error
- func DecryptString(encryptedText string, key []byte) (string, error)
- func DiffWords(s1, s2 string) ([]string, []string)
- func DirSize(dirPath string) (int64, error)
- func EncryptString(plainText string, key []byte) (string, error)
- func EndsWith(s, suffix string, ignoreCase bool) bool
- func EscapeHTML(s string) string
- func ExtractAllBetween(s, start, end string) []string
- func ExtractBetween(s, start, end string) string
- func FileModTime(filePath string) (int64, error)
- func FindFilesByExt(dirPath string, ext string) ([]string, error)
- func FindLongestWord(s string) string
- func FirstN(s string, n int) string
- func FormatFileSize(sizeInBytes int64) string
- func FormatInt(n int) string
- func FormatTemplate(template string, data map[string]interface{}) string
- func FromJSON(jsonStr string, obj interface{}) error
- func GenerateAESKey(bits int) ([]byte, error)
- func GenerateRSAKeyPair(bits int) (string, string, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomString(length int, charset string) string
- func GenerateSecureToken(length int) (string, error)
- func GetBaseName(filePath string) string
- func GetFileExt(filePath string) string
- func GetFileMD5(filePath string) (string, error)
- func GetFileSize(filePath string) (int64, error)
- func HashPassword(password string) (string, error)
- func ImageToBytes(img image.Image) ([]byte, error)
- func InsertAt(s string, index int, insert string) string
- func IsAlpha(s string) bool
- func IsAlphaNumeric(s string) bool
- func IsBlank(s string) bool
- func IsChinaPhoneNumber(s string) bool
- func IsClientError(statusCode int) bool
- func IsDir(path string) (bool, error)
- func IsEmail(s string) bool
- func IsEmpty(s string) bool
- func IsFile(path string) (bool, error)
- func IsFileOlderThan(filePath string, timestamp int64) (bool, error)
- func IsIDCard(s string) bool
- func IsIPv4(s string) bool
- func IsNumeric(s string) bool
- func IsRedirect(statusCode int) bool
- func IsServerError(statusCode int) bool
- func IsSuccess(statusCode int) bool
- func IsURL(s string) bool
- func JoinStrings(elements []string, separator string) string
- func LastN(s string, n int) string
- func ListDirs(dirPath string) ([]string, error)
- func ListFiles(dirPath string) ([]string, error)
- func MD5Hash(data string) string
- func MaskMiddleChars(s string, keepStart, keepEnd int, maskChar rune) string
- func MaskString(s string, start, end int, maskChar rune) string
- func MatchPattern(s, pattern string) (bool, error)
- func MoveFile(src, dst string) error
- func PadLeft(s string, padChar rune, totalLength int) string
- func PadRight(s string, padChar rune, totalLength int) string
- func ParseBool(s string, defaultValue bool) bool
- func ParseFloat(s string, defaultValue float64) float64
- func ParseInt(s string, defaultValue int) int
- func PathExists(path string) (bool, error)
- func PrettyJSON(obj interface{}) (string, error)
- func RSADecrypt(cipherText []byte, privateKeyPEM string) ([]byte, error)
- func RSAEncrypt(plainText []byte, publicKeyPEM string) ([]byte, error)
- func RandomSubstring(s string, length int) string
- func ReadFile(filePath string) (string, error)
- func ReadLines(filePath string) ([]string, error)
- func RemoveAccents(s string) string
- func RemoveAt(s string, index, count int) string
- func RemoveDir(dirPath string) error
- func RemoveFile(filePath string) error
- func ReverseString(s string) string
- func RunWithRateLimit(maxRequestsPerSecond int, fn func())
- func SHA1Hash(data string) string
- func SHA256Hash(data string) string
- func SimpleGet(url string) ([]byte, error)
- func SimplePost(url string, contentType string, body io.Reader) ([]byte, error)
- func SimplePostJSON(url string, data interface{}) ([]byte, error)
- func SlugifyString(s string) string
- func SplitAndTrim(s, sep string) []string
- func SplitByLength(s string, length int) []string
- func StartsWith(s, prefix string, ignoreCase bool) bool
- func StringExamples()
- func SwapCase(s string) string
- func ToJSON(obj interface{}) (string, error)
- func ToKebabCase(s string) string
- func ToLowerCamel(s string) string
- func ToSnakeCase(s string) string
- func ToUpperCamel(s string) string
- func TouchFile(filePath string) error
- func TruncateString(s string, maxLength int) string
- func Uncapitalize(s string) string
- func UnescapeHTML(s string) string
- func UrlDecode(encoded string) (string, error)
- func UrlEncode(data string) string
- func WordCount(s string) int
- func WrapText(s string, width int) string
- func WriteFile(filePath, content string) error
- type HTTPClient
- func (c *HTTPClient) Delete(path string) (*http.Response, error)
- func (c *HTTPClient) DeleteJSON(path string, v interface{}) error
- func (c *HTTPClient) Download(url, savePath string) error
- func (c *HTTPClient) Get(path string, params map[string]string) (*http.Response, error)
- func (c *HTTPClient) GetJSON(path string, params map[string]string, v interface{}) error
- func (c *HTTPClient) Post(path string, body interface{}) (*http.Response, error)
- func (c *HTTPClient) PostForm(path string, formData map[string]string) (*http.Response, error)
- func (c *HTTPClient) PostJSON(path string, body, v interface{}) error
- func (c *HTTPClient) Put(path string, body interface{}) (*http.Response, error)
- func (c *HTTPClient) PutJSON(path string, body, v interface{}) error
- func (c *HTTPClient) SetBaseURL(baseURL string) *HTTPClient
- func (c *HTTPClient) SetBasicAuth(username, password string) *HTTPClient
- func (c *HTTPClient) SetBearerAuth(token string) *HTTPClient
- func (c *HTTPClient) SetHeader(key, value string) *HTTPClient
- func (c *HTTPClient) SetHeaders(headers map[string]string) *HTTPClient
- func (c *HTTPClient) SetRetry(maxRetry int, retryWait time.Duration) *HTTPClient
- func (c *HTTPClient) SetTimeout(timeout time.Duration) *HTTPClient
- func (c *HTTPClient) UploadFile(path string, fieldName, filePath string, params map[string]string) (*http.Response, error)
- type Parallelizer
- type RateLimiter
- type SafeCounter
- type SafeMap
- func (m *SafeMap) Clear()
- func (m *SafeMap) Delete(key string)
- func (m *SafeMap) Get(key string) interface{}
- func (m *SafeMap) GetWithDefault(key string, defaultValue interface{}) interface{}
- func (m *SafeMap) Has(key string) bool
- func (m *SafeMap) Keys() []string
- func (m *SafeMap) Len() int
- func (m *SafeMap) Set(key string, value interface{})
- func (m *SafeMap) Values() []interface{}
- type Semaphore
- type Task
- type TaskResult
- type TaskWithContext
- type ThreadPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
AESDecrypt 使用AES-GCM算法解密数据
func AESEncrypt ¶
AESEncrypt 使用AES-GCM算法加密数据
func Base64Decode ¶
Base64Decode 将base64字符串解码为字节数组
func Base64UrlDecode ¶
Base64UrlDecode 将URL安全的base64字符串解码为字节数组
func Base64UrlEncode ¶
Base64UrlEncode 将字节数组编码为URL安全的base64字符串
func BatchProcess ¶
func BatchProcess[T any](items []T, batchSize int, maxGoroutines int, processBatch func(batch []T) error) error
BatchProcess 批量处理数据,将数据分成多个批次并行处理
func BytesToImage ¶ added in v1.3.0
BytesToImage 将bytes转换成image
func CheckPasswordHash ¶
CheckPasswordHash 验证密码与哈希值是否匹配
func DecryptString ¶
DecryptString 解密Base64编码的AES加密字符串
func EncryptString ¶
EncryptString 使用AES加密字符串并返回Base64编码的结果
func ExtractAllBetween ¶
ExtractAllBetween 提取两个标记之间的所有字符串
func FindFilesByExt ¶
FindFilesByExt 在指定目录中查找特定扩展名的文件
func FormatFileSize ¶
FormatFileSize 格式化文件大小(转换为KB/MB/GB等)
func FormatTemplate ¶
FormatTemplate 简单的字符串模板替换
func GenerateRSAKeyPair ¶
GenerateRSAKeyPair 生成RSA公钥和私钥对
func GenerateRandomBytes ¶
GenerateRandomBytes 生成指定数量的随机字节
func GenerateRandomString ¶
GenerateRandomString 生成随机字符串
func GenerateSecureToken ¶
GenerateSecureToken 生成安全的随机令牌
func HashPassword ¶
HashPassword 使用bcrypt对密码进行哈希处理
func ImageToBytes ¶ added in v1.3.0
ImageToBytes 将image转换成bytes
func IsFileOlderThan ¶
IsFileOlderThan 检查文件是否比指定时间戳更早
func JoinStrings ¶
JoinStrings 连接字符串数组,带分隔符
func MaskMiddleChars ¶
MaskMiddleChars 对字符串中间部分进行掩码处理,保留前n个和后m个字符
func MaskString ¶
MaskString 对字符串进行掩码处理,例如银行卡号、手机号等
func RSADecrypt ¶
RSADecrypt 使用RSA私钥解密数据
func RSAEncrypt ¶
RSAEncrypt 使用RSA公钥加密数据
func RandomSubstring ¶
RandomSubstring 随机返回字符串的一个子串
func RunWithRateLimit ¶
func RunWithRateLimit(maxRequestsPerSecond int, fn func())
RunWithRateLimit 使用速率限制执行函数
func SimplePost ¶
SimplePost 简单的POST请求
func SimplePostJSON ¶
SimplePostJSON 简单的POST JSON请求
func StartsWith ¶
StartsWith 判断字符串是否以指定前缀开始(忽略大小写)
func TruncateString ¶
TruncateString 截断字符串并添加省略号
Types ¶
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient 封装HTTP客户端
func (*HTTPClient) Delete ¶
func (c *HTTPClient) Delete(path string) (*http.Response, error)
Delete 发送DELETE请求
func (*HTTPClient) DeleteJSON ¶
func (c *HTTPClient) DeleteJSON(path string, v interface{}) error
DeleteJSON 发送DELETE请求并解析JSON响应
func (*HTTPClient) Download ¶
func (c *HTTPClient) Download(url, savePath string) error
Download 下载文件
func (*HTTPClient) GetJSON ¶
func (c *HTTPClient) GetJSON(path string, params map[string]string, v interface{}) error
GetJSON 发送GET请求并解析JSON响应
func (*HTTPClient) Post ¶
func (c *HTTPClient) Post(path string, body interface{}) (*http.Response, error)
Post 发送POST请求
func (*HTTPClient) PostJSON ¶
func (c *HTTPClient) PostJSON(path string, body, v interface{}) error
PostJSON 发送POST请求并解析JSON响应
func (*HTTPClient) Put ¶
func (c *HTTPClient) Put(path string, body interface{}) (*http.Response, error)
Put 发送PUT请求
func (*HTTPClient) PutJSON ¶
func (c *HTTPClient) PutJSON(path string, body, v interface{}) error
PutJSON 发送PUT请求并解析JSON响应
func (*HTTPClient) SetBaseURL ¶
func (c *HTTPClient) SetBaseURL(baseURL string) *HTTPClient
SetBaseURL 设置基础URL
func (*HTTPClient) SetBasicAuth ¶
func (c *HTTPClient) SetBasicAuth(username, password string) *HTTPClient
SetBasicAuth 设置基本认证
func (*HTTPClient) SetBearerAuth ¶
func (c *HTTPClient) SetBearerAuth(token string) *HTTPClient
SetBearerAuth 设置Bearer令牌认证
func (*HTTPClient) SetHeader ¶
func (c *HTTPClient) SetHeader(key, value string) *HTTPClient
SetHeader 设置请求头
func (*HTTPClient) SetHeaders ¶
func (c *HTTPClient) SetHeaders(headers map[string]string) *HTTPClient
SetHeaders 批量设置请求头
func (*HTTPClient) SetRetry ¶
func (c *HTTPClient) SetRetry(maxRetry int, retryWait time.Duration) *HTTPClient
SetRetry 设置重试参数
func (*HTTPClient) SetTimeout ¶
func (c *HTTPClient) SetTimeout(timeout time.Duration) *HTTPClient
SetTimeout 设置请求超时时间
func (*HTTPClient) UploadFile ¶
func (c *HTTPClient) UploadFile(path string, fieldName, filePath string, params map[string]string) (*http.Response, error)
UploadFile 上传文件
type Parallelizer ¶
Parallelizer 并行执行多个任务
func NewParallelizer ¶
func NewParallelizer(maxGoroutines int, timeout time.Duration) *Parallelizer
NewParallelizer 创建一个新的并行执行器
func (*Parallelizer) RunWithContext ¶
func (p *Parallelizer) RunWithContext(ctx context.Context, tasks []Task) []TaskResult
RunWithContext 带有上下文的并行执行任务列表
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter 速率限制器
func NewRateLimiter ¶
func NewRateLimiter(maxRequestsPerSecond int) *RateLimiter
NewRateLimiter 创建一个新的速率限制器
type SafeCounter ¶
type SafeCounter struct {
// contains filtered or unexported fields
}
SafeCounter 线程安全的计数器
type SafeMap ¶
type SafeMap struct {
// contains filtered or unexported fields
}
SafeMap 线程安全的映射
func (*SafeMap) GetWithDefault ¶
GetWithDefault 获取值,如果键不存在则返回默认值
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore 信号量实现
func (*Semaphore) AcquireWithTimeout ¶
AcquireWithTimeout 在指定的超时时间内获取信号量
func (*Semaphore) TryAcquire ¶
TryAcquire 尝试获取信号量,如果不可用则立即返回false
type TaskResult ¶
TaskResult 表示任务的执行结果
func RunTasksConcurrently ¶
func RunTasksConcurrently(maxGoroutines int, tasks ...Task) []TaskResult
RunTasksConcurrently 并发执行多个任务
func RunTasksWithTimeout ¶
func RunTasksWithTimeout(timeout time.Duration, tasks ...Task) []TaskResult
RunTasksWithTimeout 在指定的超时时间内并行执行多个任务
type TaskWithContext ¶
TaskWithContext 表示带有上下文的任务
type ThreadPool ¶
type ThreadPool struct {
// contains filtered or unexported fields
}
ThreadPool 表示一个线程池
func NewThreadPool ¶
func NewThreadPool(workers int, queueSize int) *ThreadPool
NewThreadPool 创建一个新的线程池