style: gin内置函数ShouldBindBodyWithJSON
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
|||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/binding"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueryMap 查询参数转换Map
|
// QueryMap 查询参数转换Map
|
||||||
@@ -30,7 +29,7 @@ func QueryMap(c *gin.Context) map[string]any {
|
|||||||
// BodyJSONMap JSON参数转换Map
|
// BodyJSONMap JSON参数转换Map
|
||||||
func BodyJSONMap(c *gin.Context) map[string]any {
|
func BodyJSONMap(c *gin.Context) map[string]any {
|
||||||
params := make(map[string]any)
|
params := make(map[string]any)
|
||||||
c.ShouldBindBodyWith(¶ms, binding.JSON)
|
c.ShouldBindBodyWithJSON(¶ms)
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@ func RequestParamsMap(c *gin.Context) map[string]any {
|
|||||||
params := make(map[string]any)
|
params := make(map[string]any)
|
||||||
// json
|
// json
|
||||||
if strings.HasPrefix(c.ContentType(), "application/json") {
|
if strings.HasPrefix(c.ContentType(), "application/json") {
|
||||||
c.ShouldBindBodyWith(¶ms, binding.JSON)
|
c.ShouldBindBodyWithJSON(¶ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 表单
|
// 表单
|
||||||
|
|||||||
Reference in New Issue
Block a user