Documentation
¶
Overview ¶
Package maxbody provides stable request-body size limiting middleware.
Use New with an explicit byte limit before handlers read request bodies, especially upload, webhook, and JSON write endpoints. Oversized requests fail at the edge instead of allowing unbounded memory or disk pressure.
Purpose: See the package summary above. Import: `github.com/aatuh/api-toolkit/v4/middleware/maxbody`. Example: See docs/api-reference.md for package example links and docs/cookbook.md for task recipes. Errors: Constructors, parsers, and handlers return or write documented errors according to their signatures; packages with plain data types do not add hidden error channels. Concurrency: Treat configured middleware and helpers as immutable after construction; request and response values remain request-scoped unless a type documents stronger guarantees. Stability: Stable core API under VERSIONING.md and scripts/apicheck.sh. When not to use: Prefer net/http, application-owned types, or narrower helpers when this package contract is not needed.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware struct {
MaxBytes int64
}
Middleware enforces a maximum request body size.
func New ¶
func New(opts Options) (*Middleware, error)
New constructs a max-body middleware with the given limit.
Example ¶
package main
import (
"fmt"
"github.com/aatuh/api-toolkit/v4/middleware/maxbody"
)
func main() {
middleware, err := maxbody.New(maxbody.Options{MaxBytes: 1 << 20})
if err != nil {
panic(err)
}
fmt.Println(middleware.MaxBytes)
}
Output: 1048576
func (*Middleware) Handler ¶
func (m *Middleware) Handler(next http.Handler) http.Handler
Handler wraps the next handler with body size limits.
func (*Middleware) Middleware ¶
func (m *Middleware) Middleware() func(http.Handler) http.Handler
Middleware implements ports.Middleware via Handler adapter.