refactor(valid): 重构验证函数实现

- 移除 ValidToStruct、ValidToMap 和 ValidToStructAndMap 函数
- 保留 CustomBind、CustomBindToMap 和 CustomBindStructAndMap 函数
- 更新 .idea/GOHCache.xml 中文件修改时间戳
- 添加对 main.go、middleware/middleware.go 和 utils/customer.go 的缓存条目
main v1.0.1005
black1552 2026-02-25 16:23:36 +08:00
parent d409dc0e2f
commit 8d1c11d76d
2 changed files with 24 additions and 39 deletions

View File

@ -340,7 +340,7 @@
<entry key="file://$PROJECT_DIR$/valid/valid.go"> <entry key="file://$PROJECT_DIR$/valid/valid.go">
<value> <value>
<ScannedPath> <ScannedPath>
<option name="lastModified" value="1772006460780" /> <option name="lastModified" value="1772007792251" />
</ScannedPath> </ScannedPath>
</value> </value>
</entry> </entry>
@ -369,7 +369,7 @@
<entry key="file://$PROJECT_DIR$/../gin_test/api/new.go"> <entry key="file://$PROJECT_DIR$/../gin_test/api/new.go">
<value> <value>
<ScannedPath> <ScannedPath>
<option name="lastModified" value="1772003979851" /> <option name="lastModified" value="1772007643850" />
<option name="schema"> <option name="schema">
<list> <list>
<option value="NewsOne" /> <option value="NewsOne" />
@ -382,7 +382,21 @@
<entry key="file://$PROJECT_DIR$/../gin_test/controller/home/index.go"> <entry key="file://$PROJECT_DIR$/../gin_test/controller/home/index.go">
<value> <value>
<ScannedPath> <ScannedPath>
<option name="lastModified" value="1772005679921" /> <option name="lastModified" value="1772007727399" />
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/main.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772006716414" />
</ScannedPath>
</value>
</entry>
<entry key="file://$PROJECT_DIR$/../gin_test/middleware/middleware.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772006700129" />
</ScannedPath> </ScannedPath>
</value> </value>
</entry> </entry>
@ -400,6 +414,13 @@
</ScannedPath> </ScannedPath>
</value> </value>
</entry> </entry>
<entry key="file://$PROJECT_DIR$/../gin_test/utils/customer.go">
<value>
<ScannedPath>
<option name="lastModified" value="1772007185481" />
</ScannedPath>
</value>
</entry>
</map> </map>
</option> </option>
<option name="tableStructMapping"> <option name="tableStructMapping">

View File

@ -15,18 +15,6 @@ import (
"github.com/gogf/gf/v2/util/gconv" "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 // CustomBind 自定义参数绑定不使用Gin的ShouldBind
func CustomBind[T any](c *gin.Context) *T { func CustomBind[T any](c *gin.Context) *T {
obj := new(T) obj := new(T)
@ -75,36 +63,12 @@ func CustomBind[T any](c *gin.Context) *T {
return obj 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 // CustomBindToMap 自定义参数绑定到map
func CustomBindToMap[T any](c *gin.Context) map[string]any { func CustomBindToMap[T any](c *gin.Context) map[string]any {
obj := CustomBind[T](c) obj := CustomBind[T](c)
return gconv.Map(obj) 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 // CustomBindStructAndMap 自定义参数绑定并返回结构体和map
func CustomBindStructAndMap[T any](c *gin.Context) (*T, map[string]any) { func CustomBindStructAndMap[T any](c *gin.Context) (*T, map[string]any) {
obj := CustomBind[T](c) obj := CustomBind[T](c)