Documentation
¶
Overview ¶
Package httputil holds tiny HTTP helpers shared across the REST and /healthz handlers.
Index ¶
- Constants
- func Error(w http.ResponseWriter, status int, msg string)
- func HomeConflictWarning(keyName, keyHome, headerHome string) string
- func JSON(w http.ResponseWriter, status int, body any)
- func NormalizeNamespace(ns string) string
- func RecordActor(ctx context.Context, name, kind string)
- func RecordedActor(ctx context.Context) (name, kind string, ok bool)
- func ValidateNamespace(ns string) error
- func WithActorHolder(ctx context.Context) context.Context
Constants ¶
const WarningHeader = "X-Memini-Warning"
WarningHeader carries a non-fatal advisory about how the server interpreted a request — something the caller almost certainly wants to know but which is not an error, so it must not fail the request. Clients surface it; the UI renders it as a banner.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, status int, msg string)
Error writes a {"error": msg} JSON body with the given status.
func HomeConflictWarning ¶ added in v0.6.8
HomeConflictWarning describes a home-namespace header the server overrode because the request's API key is bound to a home namespace of its own. The key's binding is identity, so it always wins — but silently ignoring an explicit header is exactly the kind of thing that leaves someone staring at the wrong namespace's memories wondering why. Returns "" when there is no conflict (no binding, no header, or they agree).
func JSON ¶
func JSON(w http.ResponseWriter, status int, body any)
JSON writes status and body as application/json, ignoring the encoder's write error (the response status has already been sent).
func NormalizeNamespace ¶ added in v0.6.0
NormalizeNamespace trims surrounding whitespace and slashes and collapses duplicate separators into the canonical form stored namespaces use, so " work//memini/" addresses the same rows as "work/memini". It does not validate; pair with ValidateNamespace.
func RecordActor ¶ added in v0.7.15
RecordActor records the authenticated actor — name is the named key that authenticated ("" for the admin env key or auth-disabled dev mode), kind the same "key"/"env"/"none" classification the activity log's attribution uses — into the holder, if the context carries one. A context with no holder (a surface not wrapped by the request logger) is a silent no-op: recording is best-effort telemetry, never a reason to fail a request.
func RecordedActor ¶ added in v0.7.15
RecordedActor returns what RecordActor stored for this request, ok=false when no holder is present or nothing was recorded (the request never reached an authenticating middleware — e.g. rejected before auth, or a route outside the authenticated groups).
func ValidateNamespace ¶
ValidateNamespace returns a non-nil error when ns is not a valid namespace. Valid namespaces are 1–256 bytes, contain no NUL character.
Types ¶
This section is empty.