feat: update API response structure to nest payloads under a single "data" key

This commit is contained in:
2026-09-09 16:15:33 +08:00
parent b88e86f386
commit bc7eb9dfdd
8 changed files with 36 additions and 29 deletions
+6 -3
View File
@@ -203,7 +203,9 @@ func StartTokenCleaner() {
}()
}
// SendSuccessResponse sends a standardized JSON success response.
// SendSuccessResponse sends a standardized JSON success response. Every payload
// is nested under a single "data" key, so success responses use the envelope
// {"success": true, "message": "...", "data": {...}}.
func SendSuccessResponse(w http.ResponseWriter, message string, data map[string]interface{}) {
w.Header().Set("Content-Type", "application/json")
resp := map[string]interface{}{
@@ -212,9 +214,10 @@ func SendSuccessResponse(w http.ResponseWriter, message string, data map[string]
if message != "" {
resp["message"] = message
}
for k, v := range data {
resp[k] = v
if data == nil {
data = map[string]interface{}{}
}
resp["data"] = data
json.NewEncoder(w).Encode(resp)
}