sorting

package
v3.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes Sorting values from url.Values.

func NewDecoder

func NewDecoder(params url.Values, criteria ...Sort) *Decoder

NewDecoder returns a new decoder that reads from query params.

The first sort criteria if present will be the default Sort when decode url query params and not params present.

func (*Decoder) Decode

func (dec *Decoder) Decode(v *Sorting) error

Decode reads the sort-encoded value from params and stores it in the value pointed to by v. If a value is missing from the params it'll be filled by their equivalent default value.

type Sort

type Sort struct {
	ID          string `json:"id"`
	Value       string `json:"-"`
	Description string `json:"description"`
}

Sort criteria.

func NewSort

func NewSort(id, value, description string) Sort

NewSort returns a new instance of Sort

func (Sort) MarshalJSON

func (v Sort) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

type Sorting

type Sorting struct {
	Sort      *Sort  `json:"sort,omitempty"`
	Available []Sort `json:"available,omitempty"`
}

Sorting struct allows to sort a collection.

func (Sorting) MarshalJSON

func (v Sorting) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

Jump to

Keyboard shortcuts

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