helpers

package
v0.0.0-...-da2a1ef Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02"

Variables

This section is empty.

Functions

func BindDeepObjectParam

func BindDeepObjectParam(paramName string, queryParams url.Values, dest any) error

BindDeepObjectParam binds a deepObject-style parameter to a destination. DeepObject style is only valid for query parameters and must be exploded. Objects: ?paramName[key1]=value1&paramName[key2]=value2 -> struct{Key1, Key2} Nested: ?paramName[outer][inner]=value -> struct{Outer: {Inner: value}}

func BindFormExplodeParam

func BindFormExplodeParam(paramName string, required bool, queryParams url.Values, dest any) error

BindFormExplodeParam binds a form-style parameter with explode to a destination. Form style is the default for query and cookie parameters. This handles the exploded case where arrays come as multiple query params. Arrays: ?param=a&param=b -> []string{"a", "b"} (values passed as slice) Objects: ?key1=value1&key2=value2 -> struct{Key1, Key2} (queryParams passed)

func BindFormParam

func BindFormParam(paramName string, paramLocation ParamLocation, value string, dest any) error

BindFormParam binds a form-style parameter without explode to a destination. Form style is the default for query and cookie parameters. This function handles a single query parameter value (not url.Values). Arrays: a,b,c -> []string{"a", "b", "c"} Objects: key1,value1,key2,value2 -> struct{Key1, Key2}

func BindLabelExplodeParam

func BindLabelExplodeParam(paramName string, paramLocation ParamLocation, value string, dest any) error

BindLabelExplodeParam binds a label-style parameter with explode to a destination. Label style values are prefixed with a dot. Primitives: .value -> "value" Arrays: .a.b.c -> []string{"a", "b", "c"} Objects: .key1=value1.key2=value2 -> struct{Key1, Key2}

func BindLabelParam

func BindLabelParam(paramName string, paramLocation ParamLocation, value string, dest any) error

BindLabelParam binds a label-style parameter without explode to a destination. Label style values are prefixed with a dot. Primitives: .value -> "value" Arrays: .a,b,c -> []string{"a", "b", "c"} Objects: .key1,value1,key2,value2 -> struct{Key1, Key2}

func BindSimpleExplodeParam

func BindSimpleExplodeParam(paramName string, paramLocation ParamLocation, value string, dest any) error

BindSimpleExplodeParam binds a simple-style parameter with explode to a destination. Simple style is the default for path and header parameters. Arrays: a,b,c -> []string{"a", "b", "c"} (same as non-explode) Objects: key1=value1,key2=value2 -> struct{Key1, Key2}

func BindSimpleParam

func BindSimpleParam(paramName string, paramLocation ParamLocation, value string, dest any) error

BindSimpleParam binds a simple-style parameter without explode to a destination. Simple style is the default for path and header parameters. Arrays: a,b,c -> []string{"a", "b", "c"} Objects: key1,value1,key2,value2 -> struct{Key1, Key2}

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 MarshalForm

func MarshalForm(body interface{}) (url.Values, error)

MarshalForm marshals a struct into url.Values using the struct's json tags as field names. It handles nested structs, slices, pointers, and AdditionalProperties maps.

func StyleDeepObjectParam

func StyleDeepObjectParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleDeepObjectParam serializes a value using deepObject style. DeepObject style is only valid for query parameters with object values and must be exploded. Objects: paramName[key1]=value1&paramName[key2]=value2 Nested: paramName[outer][inner]=value

func StyleFormExplodeParam

func StyleFormExplodeParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleFormExplodeParam serializes a value using form style (RFC 6570) with exploding. Form style is the default for query and cookie parameters. Primitives: paramName=value Arrays: paramName=a&paramName=b&paramName=c Objects: key1=value1&key2=value2

func StyleFormParam

func StyleFormParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleFormParam serializes a value using form style (RFC 6570) without exploding. Form style is the default for query and cookie parameters. Primitives: paramName=value Arrays: paramName=a,b,c Objects: paramName=key1,value1,key2,value2

func StyleLabelExplodeParam

func StyleLabelExplodeParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleLabelExplodeParam serializes a value using label style (RFC 6570) with exploding. Label style prefixes values with a dot. Primitives: .value Arrays: .a.b.c Objects: .key1=value1.key2=value2

func StyleLabelParam

func StyleLabelParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleLabelParam serializes a value using label style (RFC 6570) without exploding. Label style prefixes values with a dot. Primitives: .value Arrays: .a,b,c Objects: .key1,value1,key2,value2

func StyleSimpleExplodeParam

func StyleSimpleExplodeParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleSimpleExplodeParam serializes a value using simple style (RFC 6570) with exploding. Simple style is the default for path and header parameters. Arrays are comma-separated: a,b,c (same as non-explode) Objects are key=value pairs: key1=value1,key2=value2

func StyleSimpleParam

func StyleSimpleParam(paramName string, paramLocation ParamLocation, value any) (string, error)

StyleSimpleParam serializes a value using simple style (RFC 6570) without exploding. Simple style is the default for path and header parameters. Arrays are comma-separated: a,b,c Objects are key,value pairs: key1,value1,key2,value2

func UnmarshalDeepObject

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

UnmarshalDeepObject unmarshals deepObject-style query parameters to a destination.

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 Date

type Date struct {
	time.Time
}

func (Date) Format

func (d Date) Format(layout string) string

Format returns the date formatted according to layout.

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler for Date.

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(data []byte) 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
)

Directories

Path Synopsis
genhelpers generates Go files from helper and param templates.
genhelpers generates Go files from helper and param templates.

Jump to

Keyboard shortcuts

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