From fea161f4aaeb02f0e9a16af2e3061eebb738ed53 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 15 Aug 2023 21:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E6=9B=BFShouldBindJSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/maintenance/maintenance.go | 4 ++-- lib/services/requset.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/maintenance/maintenance.go b/features/maintenance/maintenance.go index e3be001c..489d7475 100644 --- a/features/maintenance/maintenance.go +++ b/features/maintenance/maintenance.go @@ -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) diff --git a/lib/services/requset.go b/lib/services/requset.go index 0fff11f0..8fa8e00c 100644 --- a/lib/services/requset.go +++ b/lib/services/requset.go @@ -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