Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 5m7s
- 新增 9 张房屋相关数据表(社区/楼宇/房源/价格快照/交易/设施/社区设施/学区/偏好) - 添加菜单权限种子数据并绑定超级管理员角色 - 生成 DAO 层代码和实体对象 - 实现房屋模块 API 接口(社区/房源/看板)和控制器服务层 - 支持多平台软关联匹配、笋盘标记和低可信度标记功能 - 更新超级管理员账号为 xxcool/xxCool@2026 - 调整 RBAC 菜单结构,移除管理员管理功能,新增日志管理菜单 - 修复 RBAC 安全漏洞,确保禁用角色权限失效 - 重构认证模块,将登录相关接口迁移到统一包结构下 - 移除废弃的管理模块和工具类接口定义 - 为通用工具包添加中文注释和文档说明
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
// Package convertx 提供带默认值兜底的类型转换工具,
|
||
// 基于 gconv 构建。
|
||
//
|
||
// 注意:gconv 转换失败时静默返回零值,
|
||
// 因此本工具仅对 nil / 空字符串输入回退到默认值。
|
||
// 需要严格转换时请传入已校验的数据。
|
||
package convertx
|
||
|
||
import (
|
||
"strings"
|
||
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
)
|
||
|
||
// ToInt 将 v 转为 int,v 为 nil 或空字符串时返回 def。
|
||
func ToInt(v any, def int) int {
|
||
if isEmpty(v) {
|
||
return def
|
||
}
|
||
return gconv.Int(v)
|
||
}
|
||
|
||
// ToInt64 将 v 转为 int64,v 为 nil 或空字符串时返回 def。
|
||
func ToInt64(v any, def int64) int64 {
|
||
if isEmpty(v) {
|
||
return def
|
||
}
|
||
return gconv.Int64(v)
|
||
}
|
||
|
||
// ToFloat64 将 v 转为 float64,v 为 nil 或空字符串时返回 def。
|
||
func ToFloat64(v any, def float64) float64 {
|
||
if isEmpty(v) {
|
||
return def
|
||
}
|
||
return gconv.Float64(v)
|
||
}
|
||
|
||
// ToString 将 v 转为 string,v 为 nil 时返回 def。
|
||
func ToString(v any, def string) string {
|
||
if v == nil {
|
||
return def
|
||
}
|
||
return gconv.String(v)
|
||
}
|
||
|
||
// ToBool 将 v 转为 bool,v 为 nil 或空字符串时返回 def。
|
||
func ToBool(v any, def bool) bool {
|
||
if isEmpty(v) {
|
||
return def
|
||
}
|
||
return gconv.Bool(v)
|
||
}
|
||
|
||
// isEmpty 判断 v 是否为 nil 或空字符串。
|
||
func isEmpty(v any) bool {
|
||
if v == nil {
|
||
return true
|
||
}
|
||
if s, ok := v.(string); ok {
|
||
return strings.TrimSpace(s) == ""
|
||
}
|
||
return false
|
||
}
|