binding

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package binding decodes HTTP request body, query, and path values into typed structs and returns api-toolkit field errors.

Use this package at transport boundaries when a handler needs a small, dependency-neutral decoder that produces the same validation Problem Details shape as the rest of the toolkit. Business validation and persistence rules should still live outside handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON[T any](r *http.Request, cfg JSONConfig) (T, error)

DecodeJSON decodes a JSON body into T.

func DecodePath

func DecodePath[T any](r *http.Request, cfg PathConfig) (T, error)

DecodePath decodes route path parameters into T.

func DecodeQuery

func DecodeQuery[T any](r *http.Request, cfg QueryConfig) (T, error)

DecodeQuery decodes query parameters into T.

func ValidationProblem

func ValidationProblem(err error) httpx.Problem

ValidationProblem maps validation errors to a Problem Details payload.

func WriteValidationProblem

func WriteValidationProblem(w http.ResponseWriter, err error)

WriteValidationProblem writes validation errors as RFC 9457 Problem Details.

Types

type JSONConfig

type JSONConfig struct {
	MaxBytes           int64
	AllowUnknownFields bool
	RequireObject      bool
}

JSONConfig configures JSON request body decoding.

type PathConfig

type PathConfig struct {
	Param func(r *http.Request, name string) string
}

PathConfig configures path decoding.

type QueryConfig

type QueryConfig struct{}

QueryConfig configures query decoding.

Jump to

Keyboard shortcuts

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