urlvalues

package
v7.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(strct interface{}, values Values) error

Decode decodes url values into the struct.

func Filters

func Filters(values Values) func(*orm.Query) (*orm.Query, error)

Filters is a shortcut for NewFilter(urlValues).Filters.

func Pagination

func Pagination(values Values) func(*orm.Query) (*orm.Query, error)

Pagination is used with Query.Apply to set LIMIT and OFFSET from the URL values:

  • ?limit=10 - sets q.Limit(10), max limit is 1000.
  • ?page=5 - sets q.Offset((page - 1) * limit), max offset is 1000000.

Types

type Filter

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

URLFilter is used with Query.Apply to add WHERE clauses from the URL values:

  • ?foo=bar - Where(`"foo" = 'bar'`)
  • ?foo=hello&foo=world - Where(`"foo" IN ('hello','world')`)
  • ?foo__neq=bar - Where(`"foo" != 'bar'`)
  • ?foo__exclude=bar - Where(`"foo" != 'bar'`)
  • ?foo__gt=42 - Where(`"foo" > 42`)
  • ?foo__gte=42 - Where(`"foo" >= 42`)
  • ?foo__lt=42 - Where(`"foo" < 42`)
  • ?foo__lte=42 - Where(`"foo" <= 42`)
  • ?foo__ieq=bar - Where(`"foo" ILIKE 'bar'`)
  • ?foo__match=bar - Where(`"foo" SIMILAR TO 'bar'`)

func NewFilter

func NewFilter(values Values) *Filter

func (*Filter) Allow

func (f *Filter) Allow(filters ...string)

func (*Filter) Filters

func (f *Filter) Filters(q *orm.Query) (*orm.Query, error)

func (*Filter) Values

func (f *Filter) Values() Values

Values returns URL values.

type Pager

type Pager struct {
	Limit  int
	Offset int

	// Default max limit is 1000.
	MaxLimit int
	// Default max offset is 1000000.
	MaxOffset int
	// contains filtered or unexported fields
}

func NewPager

func NewPager(values Values) *Pager

func (*Pager) FromURLValues

func (p *Pager) FromURLValues(values Values) error

func (*Pager) FromValues

func (p *Pager) FromValues(values Values) error

func (*Pager) GetLimit

func (p *Pager) GetLimit() int

func (*Pager) GetOffset

func (p *Pager) GetOffset() int

func (*Pager) GetPage

func (p *Pager) GetPage() int

func (*Pager) Pagination

func (p *Pager) Pagination(q *orm.Query) (*orm.Query, error)

func (*Pager) SetPage

func (p *Pager) SetPage(page int)

type Values

type Values map[string][]string

func (Values) Bool

func (v Values) Bool(name string) (bool, error)

func (Values) Duration

func (v Values) Duration(name string) (time.Duration, error)

func (Values) Float64

func (v Values) Float64(name string) (float64, error)

func (Values) Has

func (v Values) Has(name string) bool

func (Values) Int

func (v Values) Int(name string) (int, error)

func (Values) Int64

func (v Values) Int64(name string) (int64, error)

func (Values) MaybeBool

func (v Values) MaybeBool(name string) bool

func (Values) MaybeDuration

func (v Values) MaybeDuration(name string) time.Duration

func (Values) MaybeFloat64

func (v Values) MaybeFloat64(name string) float64

func (Values) MaybeInt

func (v Values) MaybeInt(name string) int

func (Values) MaybeInt64

func (v Values) MaybeInt64(name string) int64

func (Values) MaybeTime

func (v Values) MaybeTime(name string) time.Time

func (Values) Pager

func (v Values) Pager() *Pager

func (Values) SetDefault

func (v Values) SetDefault(name string, values ...string)

func (Values) String

func (v Values) String(name string) string

func (Values) Strings

func (v Values) Strings(name string) []string

func (Values) Time

func (v Values) Time(name string) (time.Time, error)

Jump to

Keyboard shortcuts

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