refactor(valid): 重构验证函数命名和返回值
- 将 ValidAndStruct 函数重命名为 ValidToStruct - 将 ValidAndMap 函数重命名为 ValidToStructAndMap - 修改 ValidToStructAndMap 函数返回结构体和映射两个值 - 更新 .idea/GOHCache.xml 中的文件修改时间戳main v1.0.00022
parent
0ad7304eca
commit
8927551779
|
|
@ -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="1770188345045" />
|
<option name="lastModified" value="1770188678912" />
|
||||||
</ScannedPath>
|
</ScannedPath>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
|
@ -382,7 +382,7 @@
|
||||||
<entry key="file://$PROJECT_DIR$/../gin_test/router/router.go">
|
<entry key="file://$PROJECT_DIR$/../gin_test/router/router.go">
|
||||||
<value>
|
<value>
|
||||||
<ScannedPath>
|
<ScannedPath>
|
||||||
<option name="lastModified" value="1770187001756" />
|
<option name="lastModified" value="1770188593199" />
|
||||||
</ScannedPath>
|
</ScannedPath>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidAndStruct 验证参数并返回结构体
|
// ValidToStruct 验证参数并返回结构体
|
||||||
func ValidAndStruct[T any](c *gin.Context) (object *T) {
|
func ValidToStruct[T any](c *gin.Context) (object *T) {
|
||||||
obj := new(T)
|
obj := new(T)
|
||||||
if err := c.BindJSON(obj); err != nil {
|
if err := c.BindJSON(obj); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -19,8 +19,8 @@ func ValidAndStruct[T any](c *gin.Context) (object *T) {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidAndMap 验证参数并返回map
|
// ValidToStructAndMap 验证参数并返回map
|
||||||
func ValidAndMap[T any](c *gin.Context) (object map[string]any) {
|
func ValidToStructAndMap[T any](c *gin.Context) (stru *T, object map[string]any) {
|
||||||
obj := new(T)
|
obj := new(T)
|
||||||
if err := c.BindJSON(obj); err != nil {
|
if err := c.BindJSON(obj); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -28,5 +28,5 @@ func ValidAndMap[T any](c *gin.Context) (object map[string]any) {
|
||||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||||
panic(gerror.Current(err).Error())
|
panic(gerror.Current(err).Error())
|
||||||
}
|
}
|
||||||
return gconv.Map(obj)
|
return obj, gconv.Map(obj)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue