Documentation
¶
Overview ¶
Package core provides shared HTTP helpers, common error values, and small cross-domain utilities that can be reused without introducing domain coupling.
Index ¶
- Constants
- Variables
- func DecodeJSON(body io.Reader, v any) error
- func GetURLParam(r *http.Request, name string) string
- func WriteBadRequest(w http.ResponseWriter, code, message string)
- func WriteConflict(w http.ResponseWriter, code, message string)
- func WriteDecodeError(w http.ResponseWriter, err error)
- func WriteError(w http.ResponseWriter, statusCode int, code, message string)
- func WriteForbidden(w http.ResponseWriter, code, message string)
- func WriteInternalError(w http.ResponseWriter, r *http.Request, err error)
- func WriteJSON(w http.ResponseWriter, statusCode int, data any)
- func WriteNoContent(w http.ResponseWriter)
- func WriteNotFound(w http.ResponseWriter, code, message string)
- func WriteOK(w http.ResponseWriter, data any)
- func WritePayloadTooLarge(w http.ResponseWriter)
- func WriteTooManyRequests(w http.ResponseWriter, code, message string)
- func WriteUnauthorized(w http.ResponseWriter, code, message string)
- func WriteValidationErrors(w http.ResponseWriter, errs []error)
- type AccountStatus
Constants ¶
const MaxJSONBodyBytes int64 = 256 * 1024
MaxJSONBodyBytes caps JSON request bodies globally because BeeBuzz JSON payloads are metadata-only; large binary inputs must use multipart or octet-stream paths.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrPayloadTooLarge = errors.New("payload too large") )
Functions ¶
func DecodeJSON ¶
DecodeJSON enforces BeeBuzz's shared JSON request policy: bounded body size, unknown-field rejection, and trailing-data rejection. Oversized bodies are mapped to ErrPayloadTooLarge even when the JSON stream is truncated mid-decode by the shared size cap.
func GetURLParam ¶
GetURLParam reads a named chi route parameter through a single shared helper so handlers do not depend directly on router-specific access patterns.
func WriteBadRequest ¶
func WriteBadRequest(w http.ResponseWriter, code, message string)
func WriteConflict ¶
func WriteConflict(w http.ResponseWriter, code, message string)
func WriteDecodeError ¶
func WriteDecodeError(w http.ResponseWriter, err error)
WriteDecodeError maps shared JSON decode failures to the correct HTTP response while keeping a stable public error shape for normal decode failures.
func WriteError ¶
func WriteError(w http.ResponseWriter, statusCode int, code, message string)
func WriteForbidden ¶
func WriteForbidden(w http.ResponseWriter, code, message string)
func WriteInternalError ¶
func WriteInternalError(w http.ResponseWriter, r *http.Request, err error)
WriteInternalError writes a 500 Internal Server Error response. Captures the error in Sentry if available. The caller should log the error.
func WriteNoContent ¶
func WriteNoContent(w http.ResponseWriter)
WriteNoContent writes a 204 No Content response.
func WriteNotFound ¶
func WriteNotFound(w http.ResponseWriter, code, message string)
func WriteOK ¶
func WriteOK(w http.ResponseWriter, data any)
WriteOK writes a 200 OK response with JSON body.
func WritePayloadTooLarge ¶
func WritePayloadTooLarge(w http.ResponseWriter)
func WriteTooManyRequests ¶
func WriteTooManyRequests(w http.ResponseWriter, code, message string)
func WriteUnauthorized ¶
func WriteUnauthorized(w http.ResponseWriter, code, message string)
func WriteValidationErrors ¶
func WriteValidationErrors(w http.ResponseWriter, errs []error)
WriteValidationErrors writes a 422 Unprocessable Entity with all validation error messages.
Types ¶
type AccountStatus ¶
type AccountStatus string
AccountStatus represents the admin moderation state of a user account.
const ( AccountStatusPending AccountStatus = "pending" AccountStatusActive AccountStatus = "active" AccountStatusBlocked AccountStatus = "blocked" )
func (AccountStatus) IsValid ¶
func (s AccountStatus) IsValid() bool
IsValid reports whether s is a recognised account status value.