Documentation
¶
Index ¶
- Variables
- func CamelToSnake(str string) string
- func ClampFloat(value, min, max float64) float64
- func ClampInt(value, min, max int) int
- func Coalesce(values ...interface{}) interface{}
- func CoalesceString(values ...string) string
- func CompactJSON(data interface{}) (string, error)
- func Contains(slice []interface{}, item interface{}) bool
- func ContainsInt(slice []int, item int) bool
- func ContainsString(slice []string, item string) bool
- func CopyStruct(src, dst interface{}) error
- func EnsureDir(path string) error
- func FormatDuration(duration time.Duration) string
- func GenerateSecureToken(length int) string
- func GetFileExtension(filename string) string
- func GetFileSize(path string) (int64, error)
- func GetMapKeys(m map[string]interface{}) []string
- func GetMapValues(m map[string]interface{}) []interface{}
- func GetStructFields(obj interface{}) []string
- func If(condition bool, trueVal, falseVal interface{}) interface{}
- func IfInt(condition bool, trueVal, falseVal int) int
- func IfString(condition bool, trueVal, falseVal string) string
- func IgnoreError(value interface{}, err error) interface{}
- func InRange(value, min, max int) bool
- func IsBusinessDay(t time.Time) bool
- func IsEmpty(str string) bool
- func IsNil(i interface{}) bool
- func IsNotEmpty(str string) bool
- func IsStrongPassword(password string) bool
- func IsValidEmail(email string) bool
- func IsValidJSON(jsonStr string) bool
- func IsValidPath(path string) bool
- func IsValidPhone(phone string) bool
- func IsValidURL(urlStr string) bool
- func IsZero(i interface{}) bool
- func JSONToMap(jsonStr string) (map[string]interface{}, error)
- func MD5Hash(data string) string
- func MaskString(str string, start, end int, mask rune) string
- func MergeMaps(maps ...map[string]interface{}) map[string]interface{}
- func Must(err error)
- func MustReturn(value interface{}, err error) interface{}
- func NextBusinessDay(t time.Time) time.Time
- func ParseTimeWithFormats(timeStr string, formats []string) (time.Time, error)
- func PrettyJSON(data interface{}) (string, error)
- func RandomString(length int) string
- func Retry(attempts int, delay time.Duration, fn func() error) error
- func RetryWithBackoff(attempts int, initialDelay time.Duration, backoffFactor float64, ...) error
- func SHA256Hash(data string) string
- func SafeParseFloat(str string, defaultValue float64) float64
- func SafeParseInt(str string, defaultValue int) int
- func SnakeToCamel(str string) string
- func TruncateString(str string, length int) string
- func UniqueInts(slice []int) []int
- func UniqueStrings(slice []string) []string
- type Converter
- type CryptoUtils
- type Encoder
- type FileUtils
- type JSONUtils
- type NumberUtils
- func (n *NumberUtils) ClampFloat(value, min, max float64) float64
- func (n *NumberUtils) ClampInt(value, min, max int) int
- func (n *NumberUtils) InRange(value, min, max int) bool
- func (n *NumberUtils) SafeParseFloat(str string, defaultValue float64) float64
- func (n *NumberUtils) SafeParseInt(str string, defaultValue int) int
- type ReflectUtils
- type StringUtils
- func (s *StringUtils) CamelToSnake(str string) string
- func (s *StringUtils) IsEmpty(str string) bool
- func (s *StringUtils) IsNotEmpty(str string) bool
- func (s *StringUtils) Mask(str string, start, end int, mask rune) string
- func (s *StringUtils) Random(length int) string
- func (s *StringUtils) SnakeToCamel(str string) string
- func (s *StringUtils) Truncate(str string, length int) string
- type TimeUtils
- type Utils
- func (u *Utils) Crypto() *CryptoUtils
- func (u *Utils) File() *FileUtils
- func (u *Utils) JSON() *JSONUtils
- func (u *Utils) Number() *NumberUtils
- func (u *Utils) Reflect() *ReflectUtils
- func (u *Utils) String() *StringUtils
- func (u *Utils) Time() *TimeUtils
- func (u *Utils) Validation() *ValidationUtils
- type ValidationUtils
- type Validator
Constants ¶
This section is empty.
Variables ¶
View Source
var Default = NewUtils()
全局工具实例
Functions ¶
func ContainsString ¶
ContainsString 检查字符串切片是否包含指定字符串
func FormatDuration ¶
FormatDuration 格式化时间间隔为人类可读格式
func GetMapValues ¶
func GetMapValues(m map[string]interface{}) []interface{}
GetMapValues 获取map的所有值
func MaskString ¶
MaskString 掩码字符串敏感信息
func MustReturn ¶
func MustReturn(value interface{}, err error) interface{}
MustReturn 如果有错误则panic,否则返回值
func ParseTimeWithFormats ¶
ParseTimeWithFormats 尝试使用多种格式解析时间
func RetryWithBackoff ¶
func RetryWithBackoff(attempts int, initialDelay time.Duration, backoffFactor float64, fn func() error) error
RetryWithBackoff 带退避的重试
func SafeParseFloat ¶
SafeParseFloat 安全解析浮点数,失败时返回默认值
func SafeParseInt ¶
SafeParseInt 安全解析整数,失败时返回默认值
Types ¶
type Converter ¶
type Converter interface {
Convert(value interface{}) (interface{}, error)
}
Converter 转换器接口
type CryptoUtils ¶
type CryptoUtils struct{}
func Crypto ¶
func Crypto() *CryptoUtils
func (*CryptoUtils) GenerateToken ¶
func (c *CryptoUtils) GenerateToken(length int) string
func (*CryptoUtils) SHA256 ¶
func (c *CryptoUtils) SHA256(data string) string
type Encoder ¶
type Encoder interface {
Encode(data interface{}) (string, error)
Decode(data string, v interface{}) error
}
Encoder 编码器接口
type FileUtils ¶
type FileUtils struct{}
func (*FileUtils) GetExtension ¶
func (*FileUtils) IsValidPath ¶
type NumberUtils ¶
type NumberUtils struct{}
func Number ¶
func Number() *NumberUtils
func (*NumberUtils) ClampFloat ¶
func (n *NumberUtils) ClampFloat(value, min, max float64) float64
func (*NumberUtils) ClampInt ¶
func (n *NumberUtils) ClampInt(value, min, max int) int
func (*NumberUtils) InRange ¶
func (n *NumberUtils) InRange(value, min, max int) bool
func (*NumberUtils) SafeParseFloat ¶
func (n *NumberUtils) SafeParseFloat(str string, defaultValue float64) float64
func (*NumberUtils) SafeParseInt ¶
func (n *NumberUtils) SafeParseInt(str string, defaultValue int) int
NumberUtils 方法
type ReflectUtils ¶
type ReflectUtils struct{}
func Reflect ¶
func Reflect() *ReflectUtils
func (*ReflectUtils) Copy ¶
func (r *ReflectUtils) Copy(src, dst interface{}) error
func (*ReflectUtils) GetFields ¶
func (r *ReflectUtils) GetFields(obj interface{}) []string
func (*ReflectUtils) IsZero ¶
func (r *ReflectUtils) IsZero(i interface{}) bool
type StringUtils ¶
type StringUtils struct{}
具体工具类型定义
func (*StringUtils) CamelToSnake ¶
func (s *StringUtils) CamelToSnake(str string) string
func (*StringUtils) IsNotEmpty ¶
func (s *StringUtils) IsNotEmpty(str string) bool
func (*StringUtils) Random ¶
func (s *StringUtils) Random(length int) string
func (*StringUtils) SnakeToCamel ¶
func (s *StringUtils) SnakeToCamel(str string) string
type ValidationUtils ¶
type ValidationUtils struct{}
func Validation ¶
func Validation() *ValidationUtils
func (*ValidationUtils) IsEmail ¶
func (v *ValidationUtils) IsEmail(email string) bool
ValidationUtils 方法
func (*ValidationUtils) IsPhone ¶
func (v *ValidationUtils) IsPhone(phone string) bool
func (*ValidationUtils) IsStrongPassword ¶
func (v *ValidationUtils) IsStrongPassword(password string) bool
func (*ValidationUtils) IsURL ¶
func (v *ValidationUtils) IsURL(url string) bool
Click to show internal directories.
Click to hide internal directories.