JSON 辅助函数:发送 JSON 响应
(w http.ResponseWriter, status int, data any)
| 30 | |
| 31 | // JSON 辅助函数:发送 JSON 响应 |
| 32 | func JSON(w http.ResponseWriter, status int, data any) { |
| 33 | w.Header().Set("Content-Type", "application/json; charset=utf-8") |
| 34 | w.WriteHeader(status) |
| 35 | _ = json.NewEncoder(w).Encode(&APIResponse{ |
| 36 | Success: status < 400, |
| 37 | Data: data, |
| 38 | }) |
| 39 | } |
| 40 | |
| 41 | // Error 辅助函数:发送错误响应 |
| 42 | func Error(w http.ResponseWriter, status int, code, message string) { |