refactor(valid): 重构验证函数实现
- 移除 ValidToStruct、ValidToMap 和 ValidToStructAndMap 函数 - 保留 CustomBind、CustomBindToMap 和 CustomBindStructAndMap 函数 - 更新 .idea/GOHCache.xml 中文件修改时间戳 - 添加对 main.go、middleware/middleware.go 和 utils/customer.go 的缓存条目main v1.0.1005
parent
d409dc0e2f
commit
8d1c11d76d
|
|
@ -340,7 +340,7 @@
|
|||
<entry key="file://$PROJECT_DIR$/valid/valid.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1772006460780" />
|
||||
<option name="lastModified" value="1772007792251" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
|
|
@ -369,7 +369,7 @@
|
|||
<entry key="file://$PROJECT_DIR$/../gin_test/api/new.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1772003979851" />
|
||||
<option name="lastModified" value="1772007643850" />
|
||||
<option name="schema">
|
||||
<list>
|
||||
<option value="NewsOne" />
|
||||
|
|
@ -382,7 +382,21 @@
|
|||
<entry key="file://$PROJECT_DIR$/../gin_test/controller/home/index.go">
|
||||
<value>
|
||||
<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>
|
||||
</value>
|
||||
</entry>
|
||||
|
|
@ -400,6 +414,13 @@
|
|||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/utils/customer.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1772007185481" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
<option name="tableStructMapping">
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue