ErrorWithDetails 辅助函数:发送带详细信息的错误响应
(w http.ResponseWriter, status int, code, message, details string)
| 53 | |
| 54 | // ErrorWithDetails 辅助函数:发送带详细信息的错误响应 |
| 55 | func ErrorWithDetails(w http.ResponseWriter, status int, code, message, details string) { |
| 56 | w.Header().Set("Content-Type", "application/json; charset=utf-8") |
| 57 | w.WriteHeader(status) |
| 58 | _ = json.NewEncoder(w).Encode(&APIResponse{ |
| 59 | Success: false, |
| 60 | Error: &APIError{ |
| 61 | Code: code, |
| 62 | Message: message, |
| 63 | Details: details, |
| 64 | }, |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | // Paginated 辅助函数:发送分页响应 |
| 69 | func Paginated(w http.ResponseWriter, items any, total, page, pageSize int) { |