core

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

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

View Source
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

View Source
var (
	ErrUnauthorized    = errors.New("unauthorized")
	ErrNotFound        = errors.New("not found")
	ErrPayloadTooLarge = errors.New("payload too large")
)

Functions

func DecodeJSON

func DecodeJSON(body io.Reader, v any) error

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

func GetURLParam(r *http.Request, name string) string

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 WriteJSON

func WriteJSON(w http.ResponseWriter, statusCode int, data any)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL