searchparams

package
v0.85.0-pre.12 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package searchparams decodes URL search parameters into Go structs and derives a type-level schema describing the accepted shape.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Parse/ParseInto errors.
	ErrCannotParse   = errors.New("error parsing URL search parameters")
	ErrNilRequest    = errors.New("parse: request is nil")
	ErrNilURL        = errors.New("parse: request URL is nil")
	ErrNilDest       = errors.New("parse: destination must be a non-nil pointer")
	ErrNonStructDest = errors.New("parse: destination must point to a struct")

	// SchemaFromValue errors.
	ErrInvalidSchema    = errors.New("invalid URL search params schema")
	ErrNilValueInSchema = errors.New("schema: value cannot be nil")
	ErrNonStructRoot    = errors.New("schema: root must be a struct")
)

Functions

func ParseIntoStructPtr

func ParseIntoStructPtr(r *http.Request, destStructPtr any) error

ParseIntoStructPtr parses URL search parameters from an HTTP request into the struct pointed to by dest. Used when the destination type is only known at runtime (e.g. via reflection-based type erasure). Callers with a static type should prefer ParseToStruct.

func ParseToStruct

func ParseToStruct[T any](r *http.Request) (T, error)

ParseToStruct parses URL search parameters from an HTTP request into a struct of type T.

Types

type Schema

type Schema any

Schema describes the accepted shape of a decoded struct. Node types are:

  • string codes ("s", "n", "b") for scalars, optionally prefixed with "?" to mark pointer scalars.
  • []Schema{elem} for slices and arrays.
  • []Schema{"*", val} for maps with string keys.
  • map[string]Schema for structs.

func SchemaFromValue

func SchemaFromValue(value any) (Schema, error)

SchemaFromValue derives a Schema from the type of value. The value's runtime contents are ignored; only its type is inspected. The root must be a struct (or a pointer to one).

Jump to

Keyboard shortcuts

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