Documentation
¶
Index ¶
- Constants
- func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst any) bool
- func LimitOffset(q url.Values, limitKey, offsetKey string, defaultLimit, maxLimit int) (limit, offset int)
- func PathValue(w http.ResponseWriter, r *http.Request, key string) (string, bool)
- func PathValueInt(w http.ResponseWriter, r *http.Request, key string) (int, bool)
- func RequireStore(w http.ResponseWriter, store any, unavailable string) bool
- func WriteInternalError(w http.ResponseWriter, err error, logMsg string, attrs ...any)
- func WriteJSON(w http.ResponseWriter, status int, data any)
- func WriteJSONError(w http.ResponseWriter, status int, message string)
- func WriteServiceError(w http.ResponseWriter, err error) bool
Constants ¶
const (
// BrowsePageDefault paginates lists a person reads a screen at a time --
// revisions, workflow runs, an issue's flow.
BrowsePageDefault, BrowsePageMax = 20, 100
// ListPageDefault paginates a space's own working lists.
ListPageDefault, ListPageMax = 50, 100
// BulkPageDefault paginates lists an operator scans or exports.
BulkPageDefault, BulkPageMax = 50, 200
)
Page sizes. Three tiers rather than one number, because the routes differ in what a screen of results is worth: a browse list is read top to bottom, an operator's list is scanned and exported. Naming them makes a route's choice visible; before, eleven call sites each passed a pair of literals and no two readers could tell which differences were meant.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSONBody ¶
DecodeJSONBody reads a JSON request body, answering the request on malformed input.
func LimitOffset ¶
func LimitOffset(q url.Values, limitKey, offsetKey string, defaultLimit, maxLimit int) (limit, offset int)
LimitOffset reads a page window, falling back to the default and clamping to the maximum. Values that are not numbers are ignored rather than refused: a bad limit is not worth failing a read over.
func PathValue ¶
PathValue reads a required path segment and answers the request itself when it is missing.
func PathValueInt ¶
PathValueInt reads a positive integer path segment, such as a revision number.
func RequireStore ¶
func RequireStore(w http.ResponseWriter, store any, unavailable string) bool
RequireStore refuses when a feature's store is absent, which is the state of every feature on a deployment running without a database.
store is `any` so one check serves every store interface. It compares against a nil interface, so a typed nil pointer would pass -- no caller passes one today, and the alternative is a check per store type.
func WriteInternalError ¶
func WriteInternalError(w http.ResponseWriter, err error, logMsg string, attrs ...any)
WriteInternalError logs the error with logMsg and attrs, then writes 500 and {"error": "internal error"}. logMsg is the slog message (e.g. "auth handler error", "portal handler error").
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, data any)
WriteJSON sets Content-Type application/json, writes status code, and encodes data as JSON.
func WriteJSONError ¶
func WriteJSONError(w http.ResponseWriter, status int, message string)
WriteJSONError sets Content-Type application/json, writes status code, and a body {"error": "<message>"}.
func WriteServiceError ¶
func WriteServiceError(w http.ResponseWriter, err error) bool
WriteServiceError answers a service error and reports whether it did.
It replaces the per-service switches that each recognised one package's sentinels: a service states a Kind, this maps Kind to status once. False means the error carries no Kind, which is the caller's signal to treat it as an internal failure -- an unclassified error is a bug, not a refusal.
Types ¶
This section is empty.