queryparam

package
v0.0.0-...-11149d6 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package queryparam provides a query parameter parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldParams

type FieldParams struct {
	OwnKey          string
	Key             string
	DefaultValue    []string
	HasDefaultValue bool
	Dive            bool
}

FieldParams contains information about parsed field tags.

type NoParserError

type NoParserError struct {
	Name string
	Type reflect.Type
}

NoParserError occurs when there is no parser provided for given type

func (NoParserError) Error

func (e NoParserError) Error() string

Error returns the error message.

type NoSupportedTagOptionError

type NoSupportedTagOptionError struct {
	Tag string
}

NoSupportedTagOptionError occurs when the given tag is not supported In-built supported tags: "", "required", "unset", "notEmpty", "expand", "paramDefault"

func (NoSupportedTagOptionError) Error

Error returns the error message.

type NotStructPtrError

type NotStructPtrError struct{}

NotStructPtrError occurs when pass something that is not a pointer to a Struct to Parse

func (NotStructPtrError) Error

func (e NotStructPtrError) Error() string

Error returns the error message.

type OnSetFn

type OnSetFn func(tag string, value any, isDefault bool)

OnSetFn is a hook that can be run when a value is set.

type Options

type Options struct {
	// Param keys and values that will be accessible for the service.
	Param map[string][]string

	// DefaultValueSeparator for slice values.
	DefaultValueSeparator string

	// TagName specifies another tagname to use rather than the default queryParam.
	TagName string

	// RequiredIfNoDef automatically sets all param as required if they do not
	// declare 'paramDefault'.
	RequiredIfNoDef bool

	// OnSet allows to run a function when a value is set.
	OnSet OnSetFn

	// Prefix define a prefix for each key.
	Prefix string

	// UseFieldNameByDefault defines whether or not param should use the field
	// name by default if the `queryParam` key is missing.
	// Note that the field name will be "converted" to conform with param
	// names conventions.
	UseFieldNameByDefault bool

	// Custom parse functions for different types.
	FuncMap map[reflect.Type]ParserFunc
	// contains filtered or unexported fields
}

Options for the parser.

type ParseError

type ParseError struct {
	Name string
	Type reflect.Type
	Err  error
}

ParseError occurs when it's impossible to convert the value for given type.

func (ParseError) Error

func (e ParseError) Error() string

Error returns the error message.

type Parser

type Parser struct {
	Param url.Values
}

Parser is a struct that can be used to parse query params.

func NewParser

func NewParser(param url.Values) *Parser

NewParser creates a new parser with the given query params.

func (*Parser) GetFieldParams

func (p *Parser) GetFieldParams(v any) ([]FieldParams, error)

GetFieldParams parses a struct containing `queryParam` tags and returns information about tags it found.

func (*Parser) GetFieldParamsWithOptions

func (p *Parser) GetFieldParamsWithOptions(v any, opts Options) ([]FieldParams, error)

GetFieldParamsWithOptions parses a struct containing `queryParam` tags and returns information about tags it found.

func (*Parser) Parse

func (p *Parser) Parse(v any) error

Parse parses a struct containing `queryParam` tags and loads its values from query params.

func (*Parser) ParseWithOptions

func (p *Parser) ParseWithOptions(v any, opts Options) error

ParseWithOptions parses a struct containing `queryParam` tags and loads its values from query params.

type ParserFunc

type ParserFunc func(v string) (any, error)

ParserFunc defines the signature of a function that can be used within `CustomParsers`.

Jump to

Keyboard shortcuts

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