service.xpcool.com/common/tools/strx/strx.go
夏犀麟 4aca0c7f6f
Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 5m7s
feat(house): 实现看房模块后端功能
- 新增 9 张房屋相关数据表(社区/楼宇/房源/价格快照/交易/设施/社区设施/学区/偏好)
- 添加菜单权限种子数据并绑定超级管理员角色
- 生成 DAO 层代码和实体对象
- 实现房屋模块 API 接口(社区/房源/看板)和控制器服务层
- 支持多平台软关联匹配、笋盘标记和低可信度标记功能
- 更新超级管理员账号为 xxcool/xxCool@2026
- 调整 RBAC 菜单结构,移除管理员管理功能,新增日志管理菜单
- 修复 RBAC 安全漏洞,确保禁用角色权限失效
- 重构认证模块,将登录相关接口迁移到统一包结构下
- 移除废弃的管理模块和工具类接口定义
- 为通用工具包添加中文注释和文档说明
2026-08-26 23:42:38 +08:00

58 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package strx 基于 gstr 提供字符串工具,含命名
// 转换与敏感数据脱敏。
package strx
import (
"strings"
"github.com/gogf/gf/v2/text/gstr"
)
// SnakeCase 将 s 转为 snake_case如 "UserName" -> "user_name"。
func SnakeCase(s string) string {
return gstr.CaseSnake(s)
}
// CamelCase 将 s 转为 CamelCase如 "user_name" -> "UserName"。
func CamelCase(s string) string {
return gstr.CaseCamel(s)
}
// LowerCamelCase 将 s 转为 lowerCamelCase如 "user_name" -> "userName"。
func LowerCamelCase(s string) string {
return gstr.CaseCamelLower(s)
}
// IsEmpty 判断 s 是否为空或仅含空白字符。
func IsEmpty(s string) bool {
return strings.TrimSpace(s) == ""
}
// MaskPhone 对手机号脱敏,保留前 3 位与后 4 位。
// 例如 "13812345678" -> "138****5678"。
func MaskPhone(s string) string {
if len(s) < 7 {
return s
}
return s[:3] + "****" + s[len(s)-4:]
}
// MaskIDCard 对身份证号脱敏,保留前 6 位与后 4 位,
// 例如 "110101199003074512" -> "110101********4512"。
func MaskIDCard(s string) string {
if len(s) < 10 {
return s
}
return s[:6] + "********" + s[len(s)-4:]
}
// MaskName 对中文姓名脱敏,仅保留首字符。
// e.g. "张三丰" -> "张**".
func MaskName(s string) string {
r := []rune(s)
if len(r) <= 1 {
return s
}
return string(r[0]) + strings.Repeat("*", len(r)-1)
}