平替ShouldBindJSON

This commit is contained in:
TsMask
2023-08-15 21:36:30 +08:00
parent 14520f404c
commit fea161f4aa
2 changed files with 3 additions and 3 deletions

View File

@@ -186,7 +186,7 @@ func Config(w http.ResponseWriter, r *http.Request) {
Key string `json:"key"`
Value string `json:"value"`
}
err := services.JSONBody(r, &bodyArgs)
err := services.ShouldBindJSON(r, &bodyArgs)
if err != nil {
log.Error("io.ReadAll is failed:", err)
services.ResponseNotFound404UriNotExist(w, r)
@@ -292,7 +292,7 @@ func TopOps(w http.ResponseWriter, r *http.Request) {
Ops string `json:"ops"`
Pid string `json:"pid"`
}
err := services.JSONBody(r, &bodyArgs)
err := services.ShouldBindJSON(r, &bodyArgs)
if err != nil {
log.Error("io.ReadAll is failed:", err)
services.ResponseNotFound404UriNotExist(w, r)

View File

@@ -10,7 +10,7 @@ import (
)
// 读取json请求结构团体
func JSONBody(r *http.Request, args any) error {
func ShouldBindJSON(r *http.Request, args any) error {
body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen))
if err != nil {
return err