jsonbody

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: 7 Imported by: 0

Documentation

Overview

Package jsonbody owns HTTP-adapter JSON body bounds and decode policy: bounded body read, shape preflight against the request-envelope profile (which also enforces exactly one JSON document), then typed decode.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("jsonbody: empty request body")

ErrEmpty reports an empty body when Policy.AllowEmpty is false.

View Source
var ErrTooLarge = errors.New("jsonbody: request body too large")

ErrTooLarge reports a request body that exceeds Policy.MaxBytes.

Functions

func Decode

func Decode(w http.ResponseWriter, r *http.Request, dest any, policy Policy) error

Decode reads one bounded request body, shape-preflights it against the request-envelope profile capped to MaxBytes (rejecting trailing or multiple documents), and decodes it into dest using the request context. HTTP status and wire error mapping remain the caller's responsibility.

Types

type Policy

type Policy struct {
	MaxBytes   int64
	AllowEmpty bool
}

Policy controls one request JSON decode.

Jump to

Keyboard shortcuts

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