Documentation
¶
Overview ¶
Package httpjson holds the JSON and RFC 9457 Problem Details responders shared by the admin and portal REST decomposition seams.
pkg/admin and pkg/portal each carry their own unexported copy of this responder, and the first seam extracted out of pkg/admin (internal/admin/settingsapi) copied it a third time. Every additional seam would have added another byte-identical copy, and — because swag resolves a schema per package — another duplicate `problemDetail` definition in the published OpenAPI document. The seams point here instead, so the seam family contributes exactly one responder and one schema.
The parents' own copies are deliberately left in place: their ~500 `@Failure ... {object} problemDetail` annotations resolve against the package-local type, and rewriting those is a documentation change rather than a decomposition one.
Index ¶
- func ParseLimit(q url.Values) int
- func ParsePageOffset(q url.Values, effectiveLimit int) int
- func ParseTimeParam(q url.Values, key string) *time.Time
- func WriteError(w http.ResponseWriter, status int, msg string)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type ProblemDetail
- type StatusResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseLimit ¶
ParseLimit parses the `per_page` parameter into a limit. Zero means the caller expressed no preference and its own default applies.
func ParsePageOffset ¶
ParsePageOffset parses the 1-based `page` parameter and converts it to a row offset against effectiveLimit. Anything absent, non-numeric, or below 1 yields the first page.
func ParseTimeParam ¶
ParseTimeParam parses an RFC3339 time from a query parameter. A missing or unparseable value yields nil, which callers treat as "no bound" — a bad timestamp widens the query rather than failing it.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, msg string)
WriteError writes an RFC 9457 Problem Details error response. Title is derived from the status text; msg becomes the detail and must already be safe to return to the caller.
Types ¶
type ProblemDetail ¶
type ProblemDetail struct {
Type string `json:"type" example:"about:blank"`
Title string `json:"title" example:"Not Found"`
Status int `json:"status" example:"404"`
Detail string `json:"detail,omitempty" example:"resource not found"`
}
ProblemDetail is an RFC 9457 Problem Details response body. It mirrors the admin and portal packages' unexported equivalents field for field, so a seam's errors are indistinguishable on the wire from the routes that stayed behind in the parent.
type StatusResponse ¶
type StatusResponse struct {
Status string `json:"status" example:"ok"`
}
StatusResponse is the generic acknowledgement body ("status": "ok") that admin and portal write routes return when there is nothing else to say. It mirrors the parents' unexported equivalents.