Skip to content

deferz/x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

GoUtils - Go 实用工具库集合

一个高性能的 Go 实用工具库集合,提供常用的数据处理、字段操作等功能。专注于性能优化和易用性,适用于高并发场景。

🛠️ 安装

go get github.com/your-username/goutils

📦 包含的包

🎯 FieldUtils - 字段操作工具库

高性能的字段过滤、脱敏和嵌套字段操作工具库。

主要功能:

  • 字段选择和过滤
  • 数据脱敏(支持自定义策略)
  • 嵌套字段操作
  • 高并发支持
  • 智能缓存机制

📖 详细文档

📋 API 概览

FieldUtils API 表格

功能类别 API 函数 用途 示例
字段过滤 Select(data, fields) 选择指定字段,返回 map Select(user, ["id", "name"])
Remove(data, excludeFields) 移除指定字段,返回 map Remove(user, ["password"])
字段脱敏 Mask(data, fields) 脱敏为零值 Mask(user, ["password"])
MaskWithPlaceholder(data, fields, placeholder) 使用占位符脱敏 MaskWithPlaceholder(user, ["phone"], "***")
MaskWithCustom(data, fields, maskFunc) 自定义脱敏函数 MaskWithCustom(user, ["email"], customFunc)
嵌套操作 SelectNested(data, fields) 嵌套字段选择 SelectNested(user, ["profile.email"])
MaskNested(data, fields) 嵌套字段脱敏 MaskNested(user, ["profile.password"])
MaskNestedWithPlaceholder(data, fields, placeholder) 嵌套字段占位符脱敏 MaskNestedWithPlaceholder(user, ["contacts.0.phone"], "***")
MaskNestedWithCustom(data, fields, maskFunc) 嵌套字段自定义脱敏 MaskNestedWithCustom(user, ["profile.email"], customFunc)
工具函数 GetFieldNames(data) 获取所有字段名 GetFieldNames(user)
HasField(data, fieldName) 检查字段是否存在 HasField(user, "name")
GetFieldValue(data, fieldName) 获取字段值 GetFieldValue(user, "age")
SetFieldValue(data, fieldName, value) 设置字段值 SetFieldValue(user, "name", "李四")
IsEmpty(data, fieldName) 检查字段是否为空 IsEmpty(user, "email")
GetNonEmptyFields(data) 获取非空字段 map GetNonEmptyFields(user)
GetEmptyFields(data) 获取空字段列表 GetEmptyFields(user)

📄 许可证

MIT License

🤝 贡献

欢迎提交 Issue 和 Pull Request!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages