Documentation
¶
Overview ¶
本文件提供基于 SHA-256 密钥和 AES-GCM 的字符串加解密能力。
本文件提供结构字段自动映射、自定义映射和字段索引缓存。
本文件提供保序、有界且可取消的批量任务执行能力。
本文件提供基础类型转换、数值相加和安全的字节字符串转换。
本文件定义兼容 shopspring/decimal 的具名 Decimal 类型。
本文件提供运行路径、文件和目录操作的兼容辅助函数。
本文件提供兼容的 MD5、SHA-256、用户标识和组合哈希函数。
本文件提供保留旧错误语义的 JSON 序列化辅助函数。
本文件提供 PBKDF2 密钥、随机盐值和 JWT key 派生能力。
本文件仅为兼容保留旧 DES、3DES 和 padding API,新代码不应继续使用。
本文件提供本机 IP、可信代理客户端地址和端口探测能力。
本文件提供整数、浮点数和可空数字文本校验。
本文件保留旧的进程级伪随机数兼容入口。
本文件提供反射类型识别、字段访问、结构遍历和实例创建能力。
本文件提供测试运行环境判断。
本文件保留 Snowflake worker 的兼容构造入口。
本文件提供 Unicode 安全的首字符转换和 rune 辅助函数。
本文件保留旧的毫秒时间戳文本转换入口。
本文件提供邮箱和手机号文本的兼容校验函数。
Index ¶
- Variables
- func Add(v1, v2 reflect.Value) reflect.Value
- func AnyToTypeData(value interface{}, src reflect.Type) (interface{}, error)
- func ArrayEach(items interface{}, f func(item interface{}))
- func AutoMapConvert(source, target interface{}, getmap func(*AutoMapArge) *AutoMapHander) interface{}
- func Bytes2String(b []byte) string
- func ClientPublicIP(r *http.Request, trustedProxies ...string) string
- func ConvertToString(value interface{}) string
- func CreateDir(name string) (string, error)
- func Decrptog3DES(src, key []byte) []byte
- func DecrptogDES(src, key []byte) []byte
- func DecryptAES(ciphertext, key string) (string, error)
- func DeepFor(stype reflect.Type, ...)
- func DeepForItem(item interface{}, ...)
- func DeleteFile(file string) error
- func DeriveJWTKey(password, userID string) string
- func DeriveKey(password, salt string, keyLen int) []byte
- func DeriveKeySecure(password string, salt []byte, keyLen int) []byte
- func DeriveKeyWithSalt(password string, keyLen int) ([]byte, []byte, error)
- func EncryptAES(plaintext, key string) (string, error)
- func Encyptog3DES(src, key []byte) []byte
- func EncyptogDES(src, key []byte) []byte
- func FirstLower(s string) string
- func FirstUpper(s string) string
- func ForEach(item interface{}, fn func(name string, value interface{}))
- func ForItem(item interface{}, value func(name string) interface{})
- func GenerateSalt(length int) ([]byte, error)
- func GetElem(typ reflect.Type) reflect.Type
- func GetLocalIP() string
- func GetLocalIPs() ([]string, error)
- func GetOutBoundIP() (ip string, err error)
- func GetPackageName(target interface{}) string
- func GetParentType(target interface{}) interface{}
- func GetPropertyType(target interface{}, name string) *reflect.StructField
- func GetPropertyTypeByElemName(target interface{}, elemTypeName string) *reflect.StructField
- func GetPropertyValue(target interface{}, name string) interface{}
- func GetRandNum(n int) int
- func GetTypeAndValue(target interface{}) (reflect.Type, reflect.Value)
- func GetTypeName(item interface{}) string
- func Getpath() string
- func HasLocalIP(ip net.IP) bool
- func HasLocalIPAddr(ip string) bool
- func HasProperty(target interface{}, name string) bool
- func HashCode64(s string) uint64
- func HashCodeHex(s string) string
- func HashCodes(strings ...string) string
- func IsArray(items interface{}) bool
- func IsDir(path string) bool
- func IsEmail(device string) bool
- func IsEqual(v1, v2 interface{}) bool
- func IsExista(file string) bool
- func IsFile(path string) bool
- func IsFloat(s string) bool
- func IsInteger(s string) bool
- func IsMobile(device string) bool
- func IsNumber(s string) bool
- func IsNumberOrNil(s string) bool
- func IsNumberOrNilFloat(s string) bool
- func IsNumberOrNilInt(s string) bool
- func IsPtr(instance interface{}) bool
- func IsTest() bool
- func IsTypeKind(typ reflect.Type, kind TypeKind) bool
- func Md5(strs ...string) string
- func MediumHash(s string) string
- func NewAlgorithmSnowFlake(machineId uint, dataCenterId uint) idgen.ISnowWorker
- func NewArrayItem(items interface{}) interface{}
- func NewInterface(obj interface{}) interface{}
- func NewInterfaceByType(typ reflect.Type) interface{}
- func PaddingText(str []byte, blockSize int) []byte
- func PrintObj(o interface{}) string
- func ReadFile(file string) (string, error)
- func RecycleObject(obj interface{})
- func ScanPort(protocol string, hostname string, port int) bool
- func SecureHash(s string) string
- func SetPropertyValue(sender interface{}, name string, value interface{}) error
- func ShortHash(s string) string
- func StopMemoryMonitor()
- func String2Bytes(s string) []byte
- func ToTime(s string) time.Time
- func TrimFirstRune(s string) string
- func UnPaddingText(str []byte) []byte
- func UserIDHash(externalID string) string
- func UserIDUUID(externalID string) string
- type AutoMapArge
- type AutoMapHander
- type ConcurrencyTasks
- type Decimal
- type TypeKind
Constants ¶
This section is empty.
Variables ¶
var TESTPATH string
TESTPATH 指定测试运行时使用的根路径。
Functions ¶
func AnyToTypeData ¶
AnyToTypeData 将值转换为指定基础类型。
func AutoMapConvert ¶
func AutoMapConvert(source, target interface{}, getmap func(*AutoMapArge) *AutoMapHander) interface{}
AutoMapConvert 将同名字段从源对象映射到目标对象,并允许调用方覆盖映射结果。
func ClientPublicIP ¶
ClientPublicIP 按可信代理链解析请求的客户端 IP。
func ConvertToString ¶
func ConvertToString(value interface{}) string
ConvertToString 将支持的基础类型转换为字符串。
func Decrptog3DES ¶
Decrptog3DES 使用旧 key 派生 IV 的 3DES-CBC 算法解密数据。
func DecryptAES ¶
DecryptAES 解密 EncryptAES 生成的 URL-safe Base64 文本。
func DeepFor ¶
func DeepFor(stype reflect.Type, forfunc func(field, parent reflect.StructField, kind TypeKind))
DeepFor 深度枚举指定反射类型的导出字段。
func DeepForItem ¶
func DeepForItem(item interface{}, forfunc func(field, parent reflect.StructField, kind TypeKind))
DeepForItem 深度枚举对象的导出字段。
func DeriveJWTKey ¶
DeriveJWTKey 使用用户标识参与盐值构造,派生 URL-safe JWT key。
func DeriveKeySecure ¶
DeriveKeySecure 使用 100,000 次 PBKDF2 迭代派生密钥。
func DeriveKeyWithSalt ¶
DeriveKeyWithSalt 生成 16 字节随机盐值并派生密钥。
func EncryptAES ¶
EncryptAES 使用 key 的 SHA-256 摘要通过 AES-GCM 加密文本。
func Encyptog3DES ¶
Encyptog3DES 使用旧 key 派生 IV 的 3DES-CBC 算法加密数据。
func ForEach ¶
func ForEach(item interface{}, fn func(name string, value interface{}))
ForEach 逐个回调对象的导出字段名和值。
func ForItem ¶
func ForItem(item interface{}, value func(name string) interface{})
ForItem 使用回调返回值更新对象的可设置字段。
func GetOutBoundIP ¶
GetOutBoundIP 通过 UDP 路由选择取得默认出口 IP。
func GetParentType ¶
func GetParentType(target interface{}) interface{}
GetParentType 返回旧继承结构中与当前类型同名的匿名结构字段类型。
func GetPropertyType ¶
func GetPropertyType(target interface{}, name string) *reflect.StructField
GetPropertyType 按 Go 字段名或 JSON tag 查找结构字段。
func GetPropertyTypeByElemName ¶
func GetPropertyTypeByElemName(target interface{}, elemTypeName string) *reflect.StructField
GetPropertyTypeByElemName 通过字段元素类型名查找字段 例如字段 PriceSources []*IndexPriceSourceModel,elemTypeName="IndexPriceSourceModel" 可以找到该字段
func GetPropertyValue ¶
func GetPropertyValue(target interface{}, name string) interface{}
GetPropertyValue 返回结构体指定字段的值,字段缺失时返回空字符串。
func GetTypeAndValue ¶
GetTypeAndValue 返回对象解引用一层后的类型和值。
func HasProperty ¶
HasProperty 报告结构体是否包含指定 Go 字段。
func IsNumberOrNilFloat ¶
IsNumberOrNilFloat 报告文本为空或能否解析为浮点数。
func IsTypeKind ¶
IsTypeKind 报告反射类型是否属于指定归一类别。
func NewAlgorithmSnowFlake ¶
func NewAlgorithmSnowFlake(machineId uint, dataCenterId uint) idgen.ISnowWorker
NewAlgorithmSnowFlake 按旧十进制拼接规则组合 machineId 和 dataCenterId。
func NewArrayItem ¶
func NewArrayItem(items interface{}) interface{}
NewArrayItem 创建数组或切片元素类型的零值指针实例。
func NewInterfaceByType ¶
NewInterfaceByType 按类型创建一个零值实例(指针)。 说明:此前基于 sync.Pool 的对象池因缺少归还路径(RecycleObject 从未被调用)而从未生效, 且路由层已有独立对象池,故此处直接用 reflect.New 创建全新零值对象,语义等价且更简洁。
func RecycleObject ¶
func RecycleObject(obj interface{})
RecycleObject 保留旧对象池 API 的源码兼容性。
NewInterfaceByType 现在直接创建全新零值对象,路由层对象复用由独立池负责; 因此这里不再执行实际归还动作。
func SetPropertyValue ¶
SetPropertyValue 按不区分大小写的字段名转换并设置值。
func StopMemoryMonitor ¶
func StopMemoryMonitor()
StopMemoryMonitor 为旧反射缓存监控的兼容入口。 Deprecated: utils 不再启动包级内存监控,调用该函数不会执行操作。
Types ¶
type AutoMapArge ¶
type AutoMapArge struct {
Field string
Value string
FieldValue interface{}
SourceName string
TargetName string
SourceType reflect.Type
TargetType reflect.Type
FieldType reflect.StructField
SourceValue interface{}
TargetValue interface{}
}
AutoMapArge 描述自定义字段映射时的源字段和目标对象上下文。
type AutoMapHander ¶
type AutoMapHander struct {
TargetField string
TargetValue interface{}
TargetItems map[string]interface{}
}
AutoMapHander 描述自定义映射返回的单字段或多字段赋值。
type ConcurrencyTasks ¶
type ConcurrencyTasks[T interface{}] struct {
Ctx context.Context
Params []T
Results []interface{}
Func func(param T) (interface{}, error)
Concurrency int
}
ConcurrencyTasks 按 Params 顺序保存并发任务的结果或错误。
Func 已经开始执行后,取消 Ctx 不会强制中断它;Func 需要自行响应业务上下文。
func (*ConcurrencyTasks[T]) GetErr ¶
func (t *ConcurrencyTasks[T]) GetErr() error
GetErr 返回 Results 中第一个错误;没有错误时返回 nil。
func (*ConcurrencyTasks[T]) Run ¶
func (t *ConcurrencyTasks[T]) Run()
Run 使用固定数量的 worker 执行任务,并保持 Results 与 Params 的索引一致。
func (*ConcurrencyTasks[T]) Successes ¶
func (t *ConcurrencyTasks[T]) Successes() int
Successes 返回没有保存 error 的结果数量。
type TypeKind ¶
type TypeKind int
TypeKind 表示工具包归一后的反射类型类别。
func GetTypeKind ¶
GetTypeKind 将 reflect.Type 归一为 TypeKind。