util

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 24 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 BoolToString

func BoolToString(b bool) 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 ContainsNumberAny

func ContainsNumberAny(s uint, strs ...uint) bool

func DecodeFileBase64

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

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

func DeduplicateIds

func DeduplicateIds(ids string) string

func EnsureDir added in v0.2.9

func EnsureDir(dirPath string) error

func EqualsAnyIgnoreCase

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

func ExtractEmails

func ExtractEmails(text string) []string

func FileExists

func FileExists(filePath string) bool

func FormatDate

func FormatDate(tm time.Time) string

func FormatMail

func FormatMail(name, mail string) string

func FormatTime

func FormatTime(tm time.Time) string

func GenerateRandomString

func GenerateRandomString(length int, charset string) string

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

func GetCachePath

func GetCachePath(rootPath, filename string) string

func GetEnv added in v0.2.9

func GetEnv(key string) string

func GetEnvBool added in v0.2.9

func GetEnvBool(key string) bool

func GetEnvBoolOrDefault added in v0.2.9

func GetEnvBoolOrDefault(key string, defaultValue bool) bool

func GetEnvInt added in v0.2.9

func GetEnvInt(key string) int

func GetEnvIntOrDefault added in v0.2.9

func GetEnvIntOrDefault(key string, defaultValue int) int

func GetEnvOrDefault added in v0.2.9

func GetEnvOrDefault(key, defaultValue string) string

func IsBlank

func IsBlank(str string) bool

func IsMatchPath

func IsMatchPath(path, smath string) bool

func IsNotBlank

func IsNotBlank(str string) bool

func MD5

func MD5(data []byte) string

func MD5Str

func MD5Str(data string) string

func Millisecond

func Millisecond() uint32

func ParseMail

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

func ParseTemplate

func ParseTemplate(templateStr string, bodyString string) (string, error)

func ParserCron

func ParserCron(cronStr string) error

func RemoveDuplicates

func RemoveDuplicates(nums []string) []string

func ReplaceAllRegex

func ReplaceAllRegex(path, regex, math string) string

func SplitAndDeduplicate

func SplitAndDeduplicate(text, sep string) []string

func SplitPath

func SplitPath(path string) []string

func StringToBool added in v0.2.9

func StringToBool(s string) bool

func StringToInt added in v0.2.9

func StringToInt(s string) int

func StringToUInt added in v0.2.9

func StringToUInt(s string) uint

func StringToUintIds

func StringToUintIds(ids string) []uint

func ValidateURL

func ValidateURL(urlStr string) error

func WriteBase64File

func WriteBase64File(base64Str string, dst string) error

func WriteFile

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

Types

type Config

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

func LoadFile

func LoadFile(fileName string) (*Config, error)

func (*Config) GetBooleanOrDefault

func (cfg *Config) GetBooleanOrDefault(section, name string, defaultValue bool) bool

func (*Config) GetInt

func (cfg *Config) GetInt(section, name string) (int, error)

func (*Config) GetInt64OrDefault

func (cfg *Config) GetInt64OrDefault(section, name string, defaultValue int64) int64

func (*Config) GetIntOrDefault

func (cfg *Config) GetIntOrDefault(section, name string, defaultValue int) int

func (*Config) GetString

func (cfg *Config) GetString(section, name string) string

func (*Config) GetStringOrDefault

func (cfg *Config) GetStringOrDefault(section, name string, defaultValue string) string

func (*Config) Save

func (cfg *Config) Save() error

func (*Config) SetBoolean

func (cfg *Config) SetBoolean(section, key string, value bool) error

func (*Config) SetInt

func (cfg *Config) SetInt(section, key string, value int) error

func (*Config) SetString

func (cfg *Config) SetString(section, key string, value string) error

type Request

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

func NewRequest

func NewRequest() *Request

func (*Request) Call

func (r *Request) Call(link string, jsonData []byte) ([]byte, error)

func (*Request) CallApi

func (r *Request) CallApi(link string, header map[string]string, method string, body []byte) ([]byte, error)

func (*Request) CallApiForResponse

func (r *Request) CallApiForResponse(link string, header map[string]string, method string, body []byte) (*Response, error)

func (*Request) CallBreak

func (r *Request) CallBreak(link string, jsonData []byte) ([]byte, error)

func (*Request) Get

func (r *Request) Get(link string) ([]byte, error)

func (*Request) JustCall

func (r *Request) JustCall(link string, jsonData []byte) error

type Response

type Response struct {
	StatusCode int
	Body       []byte
}

type RetryTransport

type RetryTransport struct {
	Transport http.RoundTripper
	Retries   int
}

func (*RetryTransport) RoundTrip

func (r *RetryTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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