Documentation
¶
Index ¶
- Constants
- func Error(w http.ResponseWriter, r *http.Request, status int, code, message string)
- func JSON(w http.ResponseWriter, status int, data any)
- func JSONFail(w http.ResponseWriter, status int, message string, data any)
- func JSONList(w http.ResponseWriter, status int, items any, total, limit, offset int)
- func JSONListWithMeta(w http.ResponseWriter, status int, items any, meta any)
- func JSONWithMessage(w http.ResponseWriter, status int, message string, data any)
- func ValidationError(w http.ResponseWriter, r *http.Request, fields map[string]string)
- type ErrorResponse
- type ListMeta
- type ListResponse
- type SuccessResponse
- type ValidationErrorResponse
Constants ¶
View Source
const ( CodeNotFound = "NOT_FOUND" CodeInternalError = "INTERNAL_ERROR" CodeInvalidJSON = "INVALID_JSON" CodeUnknownField = "UNKNOWN_FIELD" CodeBodyTooLarge = "BODY_TOO_LARGE" // CodeExportTooLarge is used with HTTP 413 when a requested export exceeds // the server's row cap. Distinct from CodeBodyTooLarge, which is about the // request body. CodeExportTooLarge = "EXPORT_TOO_LARGE" CodeValidationError = "VALIDATION_ERROR" CodeConflict = "CONFLICT" CodeForbidden = "FORBIDDEN" CodeRateLimited = "RATE_LIMITED" CodeAuthzError = "AUTHZ_ERROR" )
Standard error codes for API responses. Modules do NOT define their own codes — business errors are distinguished by the message field, not the code.
Variables ¶
This section is empty.
Functions ¶
func JSONList ¶
func JSONList(w http.ResponseWriter, status int, items any, total, limit, offset int)
JSONList writes a paginated list response.
func JSONListWithMeta ¶
func JSONListWithMeta(w http.ResponseWriter, status int, items any, meta any)
JSONListWithMeta writes a paginated list response with a custom meta object.
func JSONWithMessage ¶
func JSONWithMessage(w http.ResponseWriter, status int, message string, data any)
func ValidationError ¶
ValidationError sends a 400 response containing per-field validation errors.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Code string `json:"code"`
TraceID string `json:"trace_id,omitempty"`
} // @name ErrorResponse
ErrorResponse is the standard error envelope for API responses.
type ListMeta ¶
type ListMeta struct {
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
} // @name ListMeta
ListMeta contains pagination metadata for list responses.
type ListResponse ¶
type ListResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Data any `json:"data"`
Meta ListMeta `json:"meta"`
} // @name ListResponse
ListResponse is the envelope for paginated list endpoints.
type SuccessResponse ¶
type SuccessResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Data any `json:"data"`
} // @name SuccessResponse
SuccessResponse is the standard success envelope for API responses.
Click to show internal directories.
Click to hide internal directories.