params

package
v0.0.0-...-102bb52 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package params implements a decoder of HTTP parameters from the query string, path parameters and request body into a struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes request parameters into a struct and validates the values if the struct implements Validator. It uses strict decoding, where unknown fields and unexpected data raises errors.

The Decoder is safe for concurrent use. Use the "schema" struct tag for form decoding (including query string values), "json" for JSON unmarshaling, "path" to decode path values, and "cookie" to decode a cookie value into a field. Both the "schema" and "json" tags will assign to a field without any struct tag if it matches, so it is recommended to set fields that should NOT be targeted by form/json decoding with the "-" value to explicitly disable them.

For cookie decoding other than the "raw" option, it assumes the value is base64URL encoded without any padding.

func New

func New() *Decoder

New initializes a new Decoder, which is safe to use concurrently.

func (*Decoder) Decode

func (d *Decoder) Decode(r *http.Request, dst any) error

Decode decodes the http parameters from r into dst. Body decoding depends on the content-type header.

type Validator

type Validator interface {
	Validate() error
}

Validator defines the method required for a type to validate itself.

Jump to

Keyboard shortcuts

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