Help us shape the future of Go! Take the 2026 Go Developer Survey

bodysize

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package bodysize carries the request body size limit through a context.Context, from the body-limit middleware (arkoren.dev/core/http/middleware/bodylimit) to the request body helpers (arkoren.dev/core/http/request). It is internal so that only the middleware can set the limit; handlers cannot widen it by writing to the context. The value is a byte count; request helpers interpret absence using their own defaults. This context metadata does not itself wrap or limit an io.Reader.

ctx := bodysize.NewContext(ctx, 1<<20)
limit, present := bodysize.FromContext(ctx)
fmt.Println(limit, present)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) (int64, bool)

FromContext returns the limit stored in ctx and whether there is one. Absence returns zero and false, distinct from an explicitly stored zero.

Example: limit, present := bodysize.FromContext(bodysize.NewContext(ctx, 1024)); fmt.Println(limit, present)

func NewContext

func NewContext(ctx context.Context, n int64) context.Context

NewContext returns a copy of ctx that carries n as the body size limit. It retains no reader and performs no validation; the middleware owns policy and actual enforcement. A nil parent follows context.WithValue's panic rule.

Example: ctx := bodysize.NewContext(ctx, 1<<20)

Types

This section is empty.

Jump to

Keyboard shortcuts

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