jsonguard

package
v0.1.0 Latest Latest
Warning

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

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

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

View Source
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

func TooLarge

func TooLarge(err error) bool

TooLarge reports whether err maps to a request-entity-too-large response.

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.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Kind

type Kind = jsonshape.Kind

Kind classifies guard failures for frontend handler mapping.

func Classify

func Classify(err error) Kind

Classify returns the guard kind for typed guard errors.

type Limits

type Limits = jsonshape.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

func NormalizeLimits(limits Limits) Limits

NormalizeLimits fills zero or negative fields with defaults.

type Result

type Result = jsonshape.Result

Result reports basic facts gathered during token-level scanning.

func Preflight

func Preflight(data []byte, limits Limits) (Result, error)

Preflight validates JSON size and shape using streaming decoder tokens.

func PreflightWithContext

func PreflightWithContext(ctx context.Context, data []byte, limits Limits) (Result, error)

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.

Jump to

Keyboard shortcuts

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