urlquery

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package urlquery allows converting structs to/from URL query parameters.

Index

Constants

View Source
const (
	ArrayImplicit = iota
	ArrayExplicit
	ArrayIndexed
	ArrayCSV
	ArrayNone
)

The following options control array expression when encoding.

View Source
const (
	KeysIndexed = iota
	KeysDotted
	KeysNone
)

The following options control sub-key expression when encoding.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emptier

type Emptier interface {
	IsEmpty() bool
}

Emptier may be used in conjunction with the omitempty struct tag. Any type that implements this interface may return false here to be omitted in output when the tag is present.

type Encoding

type Encoding struct {
	// FormatBool specifies a custom Bool formatting.  Defaults to calling
	// strconv.FormatBool, which returns the strings "true" and "false".
	FormatBool func(bool) string
	// ArrayMode indicates how to encode arrays. The options are:
	//
	//	- ArrayImplicit -- No special treatment (default)
	//	- ArrayExplicit -- Adds a [] suffix to the key name
	//	- ArrayIndexed  -- Each array element is indexed by adding a [n] suffix to the key name
	//	- ArrayCSV      -- All values are added to a single key, as a list of CSV values
	//	- ArrayNone     -- An array will return an error
	ArrayMode int
	// KeyMode indicates how to encode object keys. The options are:
	//
	//	- KeysIndexed -- Keys are wrapped in square brackets
	//	- KeysDotted  -- Keys are separated by periods
	//	- KeysNone    -- Any sub-keys will return an error.
	KeyMode int
	// Tag specifies the name of the struct tag to look for. Defaults to url.
	// Set Tag to "-" to disable struct tag parsing.
	Tag string
}

Encoding represents a specific set of encoding/decoding rules for URL query mapping.

func JSONAPI added in v0.0.2

func JSONAPI() *Encoding

JSONAPI returns an Encoding that produces query parameters compatible with JSON:API requests.

func (*Encoding) Encode

func (e *Encoding) Encode(i interface{}) (url.Values, error)

Encode converts i to a set of url.Values.

type Primitive

type Primitive interface{}

Primitive is one of the following underlying types:

  • string
  • []Primitive
  • map[string]Primitive

type URLMarshaler

type URLMarshaler interface {
	MarshalURL() (Primitive, error)
}

URLMarshaler may be implemented by any type to support conversion to query parameters.

Jump to

Keyboard shortcuts

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