params

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindParameter

func BindParameter(paramName string, value string, dest any, opts ParameterOptions) error

BindParameter binds a styled parameter from a single string value to a Go object. This is the entry point for path, header, and cookie parameters where the HTTP framework has already extracted the raw value.

The Style field in opts selects how the value is split into parts (simple, label, matrix, form). If Style is empty, "simple" is assumed.

func BindQueryParameter

func BindQueryParameter(paramName string, queryParams url.Values, dest any, opts ParameterOptions) error

BindQueryParameter binds a query parameter from pre-parsed url.Values. The Style field in opts selects parsing behavior. If Style is empty, "form" is assumed. Supports form, spaceDelimited, pipeDelimited, and deepObject.

func BindRawQueryParameter

func BindRawQueryParameter(paramName string, rawQuery string, dest any, opts ParameterOptions) error

BindRawQueryParameter works like BindQueryParameter but operates on the raw (undecoded) query string. This correctly handles form/explode=false parameters whose values contain literal commas encoded as %2C — something that BindQueryParameter cannot do because url.Values has already decoded %2C to ',' before we can split on the delimiter comma.

func BindStringToObject

func BindStringToObject(src string, dst any) error

BindStringToObject binds a string value to a destination object. It handles primitives, encoding.TextUnmarshaler, and the Binder interface.

func MarshalDeepObject

func MarshalDeepObject(i any, paramName string) (string, error)

MarshalDeepObject marshals an object to deepObject style query parameters.

func StyleParameter

func StyleParameter(paramName string, value any, opts ParameterOptions) (string, error)

StyleParameter serializes a Go value into an OpenAPI-styled parameter string. This is the entry point for client-side parameter serialization. The Style field in opts selects the serialization format. If Style is empty, "simple" is assumed.

func UnmarshalDeepObject

func UnmarshalDeepObject(dst any, paramName string, params url.Values) error

UnmarshalDeepObject unmarshals deepObject-style query parameters to a destination. Exported for use by generated code and tests.

Types

type Binder

type Binder interface {
	Bind(value string) error
}

Binder is an interface for types that can bind themselves from a string value.

type MissingRequiredParameterError

type MissingRequiredParameterError struct {
	ParamName string
}

MissingRequiredParameterError is returned when a required parameter is not present in the request. Upper layers can use errors.As to detect this and produce an appropriate HTTP error response.

func (*MissingRequiredParameterError) Error

type ParamLocation

type ParamLocation int

ParamLocation indicates where a parameter is located in an HTTP request.

const (
	ParamLocationUndefined ParamLocation = iota
	ParamLocationQuery
	ParamLocationPath
	ParamLocationHeader
	ParamLocationCookie
)

type ParameterOptions

type ParameterOptions struct {
	Style         string        // OpenAPI style: "simple", "form", "label", "matrix", "deepObject", "pipeDelimited", "spaceDelimited"
	ParamLocation ParamLocation // Where the parameter appears: query, path, header, cookie
	Explode       bool
	Required      bool
	Type          string // OpenAPI type: "string", "integer", "array", "object"
	Format        string // OpenAPI format: "int32", "date-time", etc.
	AllowReserved bool   // When true, reserved characters in query values are not percent-encoded
}

ParameterOptions carries OpenAPI parameter metadata to bind and style functions so they can handle style dispatch, explode, required, type-aware coercions, and location-aware escaping from a single uniform call site. All fields have sensible zero-value defaults.

Jump to

Keyboard shortcuts

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