utils

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake 驼峰命名转下划线命名 例如:CamelCase -> camel_case, AccessID -> access_id

func ConvertJSONArrayToSlice

func ConvertJSONArrayToSlice(arr []any, t reflect.Type) (reflect.Value, error)

ConvertJSONArrayToSlice 将JSON数组转换为指定类型的切片

func IsAllLower

func IsAllLower(s string) bool

IsAllLower 检查字符串是否全部为小写字母

func IsZero

func IsZero(v reflect.Value) bool

IsZero 检查反射值是否为零值

func ParseSlice

func ParseSlice(s string, t reflect.Type) (reflect.Value, error)

ParseSlice 解析字符串为切片类型

func SetDefaultValues

func SetDefaultValues(obj any) error

SetDefaultValues 为结构体设置默认值

func SetDefaultValuesRecursive

func SetDefaultValuesRecursive(val reflect.Value) error

SetDefaultValuesRecursive 递归设置默认值

func SetFieldValue

func SetFieldValue(field reflect.Value, value string) error

SetFieldValue 设置字段值

func SetJSONElementValue

func SetJSONElementValue(val reflect.Value, item any, elemType reflect.Type, index int) error

SetJSONElementValue 设置JSON数组元素的值,改进错误处理

func SetSliceElementValue

func SetSliceElementValue(val reflect.Value, part string, elemType reflect.Type) error

SetSliceElementValue 设置切片元素的值,带类型安全检查

func SnakeToCamel

func SnakeToCamel(s string) string

SnakeToCamel 下划线命名转驼峰命名 例如:snake_case -> snakeCase, access_id -> accessId

func StringToMapHookFunc

func StringToMapHookFunc() mapstructure.DecodeHookFunc

StringToMapHookFunc 创建mapstructure的字符串到map转换hook

func StringToSliceHookFunc

func StringToSliceHookFunc() mapstructure.DecodeHookFunc

StringToSliceHookFunc 创建mapstructure的字符串到切片转换hook

func ValidateStruct

func ValidateStruct(obj any) error

ValidateStruct 验证结构体字段

Types

type CacheManager

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

CacheManager 缓存管理器

func NewCacheManager

func NewCacheManager(maxSize int) *CacheManager

NewCacheManager 创建新的缓存管理器

func (*CacheManager) CleanCache

func (cm *CacheManager) CleanCache()

CleanCache 清理缓存(当缓存过大时)

func (*CacheManager) GetCamelToSnake

func (cm *CacheManager) GetCamelToSnake(key string) (string, bool)

GetCamelToSnake 获取camelCase到snake_case的缓存

func (*CacheManager) GetSnakeToCamel

func (cm *CacheManager) GetSnakeToCamel(key string) (string, bool)

GetSnakeToCamel 获取snake_case到camelCase的缓存

func (*CacheManager) SetCamelToSnake

func (cm *CacheManager) SetCamelToSnake(key, value string)

SetCamelToSnake 设置camelCase到snake_case的缓存

func (*CacheManager) SetSnakeToCamel

func (cm *CacheManager) SetSnakeToCamel(key, value string)

SetSnakeToCamel 设置snake_case到camelCase的缓存

Jump to

Keyboard shortcuts

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