params

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPage defines the page number if none is set.
	DefaultPage = 1
	// DefaultLimit defines how many items will be returned if
	// the limit is set to list all.
	DefaultLimit = 15
	// DefaultOrderBy defines the default order by if an error
	// occurred.
	DefaultOrderBy = "id"
	// DefaultOrderDirection defines the default order direction
	// if an error occurred.
	DefaultOrderDirection = "DESC"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Defaults

type Defaults struct {
	Page           int         `json:"page"`
	Limit          interface{} `json:"limit"`
	OrderBy        string      `json:"order_by"`
	OrderDirection string      `json:"order_direction"`
}

Defaults represents the default configuration for obtaining params.

type Filter

type Filter struct {
	Operator string `json:"operator"`
	Value    string `json:"value"`
}

Filter represents the searching fields for searching through records.

type Filters

type Filters map[string][]Filter

Filters represents the map and slice of filters

type Params

type Params struct {
	Page           int     `json:"page"`
	Limit          int     `json:"limit"`
	LimitAll       bool    `json:"all"`
	OrderBy        string  `json:"order_by"`
	OrderDirection string  `json:"order_direction"`
	Filters        Filters `json:"-"`

	Stringer `json:"-"`
	// contains filtered or unexported fields
}

Params represents the http params for interacting with the DB

func New

func New(str Stringer, def Defaults) *Params

NewParams - create a new parameter type

func (*Params) Get

func (p *Params) Get() Params

Get

Get query Parameters for http API routes and query loops in templates.

type Stringer

type Stringer interface {
	Param(string) string
}

Stringer defines the method for obtaining parameters.

Jump to

Keyboard shortcuts

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