Documentation
¶
Overview ¶
Package jsonguard provides low-cost preflight checks for untrusted frontend JSON bodies. Shape scanning is delegated to internal/core/jsonshape; this package keeps the frontend HTTP read helpers and historical type/error surface.
Frozen compat shim: callers depend on this package path for legacy imports and error types; do not extend behavior here—add new shape policy under jsonshape or wire frontends.
Index ¶
Constants ¶
const ( KindTooLarge = jsonshape.KindTooLarge KindMalformed = jsonshape.KindMalformed KindTooDeep = jsonshape.KindTooDeep KindTooManyTokens = jsonshape.KindTooManyTokens KindTooManyItems = jsonshape.KindTooManyItems KindStringTooLong = jsonshape.KindStringTooLong KindKeyTooLong = jsonshape.KindKeyTooLong KindNumberTooLong = jsonshape.KindNumberTooLong KindDuplicateName = jsonshape.KindDuplicateName KindInvalidUTF8 = jsonshape.KindInvalidUTF8 KindCanceled = jsonshape.KindCanceled )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct {
Kind Kind
Limit int
Value int
Msg string
// contains filtered or unexported fields
}
Error is a typed JSON guard failure with jsonguard-prefixed Error() text.
type Limits ¶
Limits bounds JSON body shape before adapter-specific decode.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits returns conservative non-zero defaults for frontend JSON bodies.
func NormalizeLimits ¶
NormalizeLimits fills zero or negative fields with defaults.
type Result ¶
Result reports basic facts gathered during token-level scanning.
func PreflightWithContext ¶
PreflightWithContext is Preflight with request-cancellation checks at token boundaries.
func ReadAndPreflight ¶
func ReadAndPreflight(w http.ResponseWriter, r *http.Request, limits Limits) ([]byte, Result, error)
ReadAndPreflight reads a bounded request body and then applies PreflightWithContext.