refactor(handlers): extract request validation logic to new function

Extract the request validation logic from ValidateRequest into a new ValidateRequestWithBody function to allow passing pre-read request bodies. Update all handler functions to use the new validation function for consistency and to avoid duplicate body reading.
This commit is contained in:
2026-02-23 19:56:16 +08:00
parent 39a4479203
commit 275e08a1a5
3 changed files with 22 additions and 4 deletions
+4
View File
@@ -202,6 +202,10 @@ func ValidateRequest(w http.ResponseWriter, r *http.Request, requiredFields ...s
}
defer r.Body.Close()
return ValidateRequestWithBody(w, r, body, requiredFields...)
}
func ValidateRequestWithBody(w http.ResponseWriter, r *http.Request, body []byte, requiredFields ...string) (int, string, error) {
var reqMap map[string]interface{}
if err := json.Unmarshal(body, &reqMap); err != nil {
return 0, "", errors.New("invalid request format")