Documentation
¶
Overview ¶
Package httpapi contains HTTP trust-boundary primitives shared by handlers.
Index ¶
- Constants
- func NewRequestID() (string, error)
- func RedactText(text string, secrets ...Secret) string
- func StatusCode(err error) int
- func StrictJSON[T any](body io.Reader, maxBytes int64, next func(T) error) error
- func WriteError(w http.ResponseWriter, requestID string, err error)
- type APIError
- type ErrorKind
- type ErrorResponse
- type Secret
Constants ¶
const Redacted = "[REDACTED]"
Variables ¶
This section is empty.
Functions ¶
func NewRequestID ¶
NewRequestID returns a cryptographically random lowercase UUIDv4.
func RedactText ¶
RedactText removes explicit secret values and supported token/session syntax.
func StatusCode ¶
StatusCode maps a classified error to its stable HTTP status.
func StrictJSON ¶
StrictJSON bounds and strictly decodes one object before invoking next. The callback is never invoked for malformed, duplicate-key, unknown-field, or type-invalid input.
func WriteError ¶
func WriteError(w http.ResponseWriter, requestID string, err error)
WriteError emits one deterministic DANS error response.
Types ¶
type APIError ¶
type APIError struct {
// contains filtered or unexported fields
}
APIError retains an internal cause while exposing only a stable public kind.
func NewDetailedError ¶
NewDetailedError adds already-sanitized public validation details.
type ErrorKind ¶
type ErrorKind string
ErrorKind is a stable class of DANS-originated failure.
const ( KindBadRequest ErrorKind = "bad_request" KindInvalidRequest ErrorKind = "invalid_request" KindUnauthenticated ErrorKind = "unauthenticated" KindForbidden ErrorKind = "forbidden" KindNotFound ErrorKind = "not_found" KindConflict ErrorKind = "conflict" KindBodyTooLarge ErrorKind = "body_too_large" // KindRateLimited is a retryable throttle: a bucket lacks tokens now. KindRateLimited ErrorKind = "rate_limited" // KindRateLimitCapacity is not retryable: the request cost exceeds a // bucket's capacity, so it can never be admitted as sent. KindRateLimitCapacity ErrorKind = "rate_limit_capacity" KindBadGateway ErrorKind = "bad_gateway" KindGatewayTimeout ErrorKind = "gateway_timeout" KindInternal ErrorKind = "internal" )
type ErrorResponse ¶
ErrorResponse is the PowerDNS-compatible body for a DANS-originated error.
func ErrorBody ¶
func ErrorBody(err error) ErrorResponse
ErrorBody maps a classified error to a secret-safe public response.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret wraps a value so common diagnostic encoders redact it by default.
func (Secret) MarshalJSON ¶
MarshalJSON prevents accidental secret disclosure in JSON diagnostics.