filtering

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: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Boolean

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

Boolean validates boolean values and returns a Filter. The Filter returned will be true or false.

func NewBoolean

func NewBoolean(id, description string, trueDescription, falseDescription string) *Boolean

NewBoolean returns a new Boolean instance.

func (*Boolean) Present

func (b *Boolean) Present(keys url.Values) *Filter

Present gets a url and check if a boolean filter is present, if it's present validates if its value are true or false. Returns a Filter with the applied value or nil is not present.

func (*Boolean) WithValues

func (b *Boolean) WithValues() *Filter

WithValues returns the filter with true and false values.

type Decoder

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

Decoder validates filters from url.Values and returns Filters with the value found. If not filters were found, it returns nil.

func NewDecoder

func NewDecoder(params url.Values, decoders ...FilterDecoder) *Decoder

NewDecoder returns a new Decoder instance.

func (*Decoder) Decode

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

Decode reads the filter-encoded values 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 Filter

type Filter struct {
	ID          string  `json:"id"`
	Description string  `json:"description"`
	Type        string  `json:"type"`
	Values      []Value `json:"values"`
}

Filter struct that represent a filter

func NewFilter

func NewFilter(id, description, typef string, values ...Value) *Filter

NewFilter returns a new Filter instance.

func (Filter) MarshalJSON

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

MarshalJSON supports json.Marshaler interface

type FilterDecoder

type FilterDecoder interface {
	// Present gets the url params and check if a filter is present within them,
	// if it's present validates if its value is valid.
	// Returns a Filter with the applied value or nil is not present.
	Present(url.Values) *Filter
	// WithValues returns a filter with all their posible values.
	WithValues() *Filter
}

FilterDecoder interface to validate and returns Filter's.

type Filtering

type Filtering struct {
	Filters   []Filter `json:"filters,omitempty"`
	Available []Filter `json:"available,omitempty"`
}

Filtering allows to filter a collection with the selected Filters and their selected values. The Available are all the possible Filters with all their possible values.

func (Filtering) MarshalJSON

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

MarshalJSON supports json.Marshaler interface

type Text

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

Text validates text values and returns a Filter with the value found. If not filters were found, it returns nil.

func NewText

func NewText(id, description string, values ...Value) *Text

NewText returns a new Text instance.

func (*Text) Present

func (b *Text) Present(keys url.Values) *Filter

Present gets the url params and check if a text filter is present, if it's present validates its value meets one of filter values options. Returns a Filter with the applied value or nil is not present.

func (*Text) WithValues

func (b *Text) WithValues() *Filter

WithValues returns the filter with all their values.

type Value

type Value struct {
	ID          string `json:"id"`
	Description string `json:"description"`
	Result      int64  `json:"result,omitempty"`
}

Value is the struct where the posibles filter values should be stored.

func NewValue

func NewValue(id, description string) Value

NewValue returns a new Value instance.

func (Value) MarshalJSON

func (v Value) 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