limits

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package limits provides size-bounded parsing helpers for common formats.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLimitConfig indicates an invalid limits configuration.
	ErrInvalidLimitConfig = ewrap.New("invalid limits config")
	// ErrInvalidLimitInput indicates the input or target is invalid.
	ErrInvalidLimitInput = ewrap.New("invalid limits input")
	// ErrLimitExceeded indicates the input exceeded the configured limit.
	ErrLimitExceeded = ewrap.New("input exceeds limit")
	// ErrReadFailed indicates the input could not be read.
	ErrReadFailed = ewrap.New("input read failed")
	// ErrDecodeFailed indicates the input could not be decoded.
	ErrDecodeFailed = ewrap.New("input decode failed")
)

Functions

func DecodeJSON

func DecodeJSON(reader io.Reader, value any, opts ...Option) error

DecodeJSON decodes JSON with size bounds and strict defaults.

func DecodeXML

func DecodeXML(reader io.Reader, value any, opts ...Option) error

DecodeXML decodes XML with size bounds.

func DecodeYAML

func DecodeYAML(reader io.Reader, value any, opts ...Option) error

DecodeYAML decodes YAML with size bounds. Unknown fields are rejected by default unless WithYAMLAllowUnknownFields(true) is set.

func ReadAll

func ReadAll(reader io.Reader, opts ...Option) ([]byte, error)

ReadAll reads the entire input, enforcing the configured size limit.

Types

type Option

type Option func(*config) error

Option configures size limits and decoding behavior.

func WithMaxBytes

func WithMaxBytes(maxBytes int) Option

WithMaxBytes sets the maximum allowed input size in bytes.

func WithYAMLAllowUnknownFields

func WithYAMLAllowUnknownFields(allow bool) Option

WithYAMLAllowUnknownFields permits unknown YAML fields during decode.

Jump to

Keyboard shortcuts

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