httpjson

package
v1.118.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseLimit

func ParseLimit(q url.Values) int

ParseLimit parses the `per_page` parameter into a limit. Zero means the caller expressed no preference and its own default applies.

func ParsePageOffset

func ParsePageOffset(q url.Values, effectiveLimit int) int

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

func ParseTimeParam(q url.Values, key string) *time.Time

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.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON writes v as a JSON response with the given status. A Content-Type the caller already set is preserved, which is what lets WriteError layer its problem+json type on top of this.

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.

Jump to

Keyboard shortcuts

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