refactor(valid): 重构验证函数实现
- 移除 ValidToStruct、ValidToMap 和 ValidToStructAndMap 函数 - 保留 CustomBind、CustomBindToMap 和 CustomBindStructAndMap 函数 - 更新 .idea/GOHCache.xml 中文件修改时间戳 - 添加对 main.go、middleware/middleware.go 和 utils/customer.go 的缓存条目
This commit is contained in:
@@ -15,18 +15,6 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// ValidToStruct 验证参数并返回结构体
|
||||
func ValidToStruct[T any](c *gin.Context) (object *T) {
|
||||
obj := new(T)
|
||||
if err := c.ShouldBind(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||
panic(gerror.Current(err).Error())
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// CustomBind 自定义参数绑定,不使用Gin的ShouldBind
|
||||
func CustomBind[T any](c *gin.Context) *T {
|
||||
obj := new(T)
|
||||
@@ -75,36 +63,12 @@ func CustomBind[T any](c *gin.Context) *T {
|
||||
return obj
|
||||
}
|
||||
|
||||
// ValidToMap 验证参数并返回结构体
|
||||
func ValidToMap[T any](c *gin.Context) (object map[string]any) {
|
||||
obj := new(T)
|
||||
if err := c.ShouldBind(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||
panic(gerror.Current(err).Error())
|
||||
}
|
||||
return gconv.Map(obj)
|
||||
}
|
||||
|
||||
// CustomBindToMap 自定义参数绑定到map
|
||||
func CustomBindToMap[T any](c *gin.Context) map[string]any {
|
||||
obj := CustomBind[T](c)
|
||||
return gconv.Map(obj)
|
||||
}
|
||||
|
||||
// ValidToStructAndMap 验证参数并返回map
|
||||
func ValidToStructAndMap[T any](c *gin.Context) (stru *T, object map[string]any) {
|
||||
obj := new(T)
|
||||
if err := c.ShouldBind(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||
panic(gerror.Current(err).Error())
|
||||
}
|
||||
return obj, gconv.Map(obj)
|
||||
}
|
||||
|
||||
// CustomBindStructAndMap 自定义参数绑定并返回结构体和map
|
||||
func CustomBindStructAndMap[T any](c *gin.Context) (*T, map[string]any) {
|
||||
obj := CustomBind[T](c)
|
||||
|
||||
Reference in New Issue
Block a user