paging

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: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxAllowedLimit determines the maximum value that can take limit when decode.
	DefaultMaxAllowedLimit = 100
	// DefaultLimit default value that take limit when not limit param present in query params.
	DefaultLimit = 10
	// DefaultOffset default value that take offset when not offset param present in query params.
	DefaultOffset = 0
)

Variables

View Source
var (
	// ErrInvalidOffsetValueNotANumber expected error when fails parsing the offset value to int.
	ErrInvalidOffsetValueNotANumber = errors.New("invalid offset value, must be a number")
	// ErrInvalidOffsetValueLessThanZero expected error when offset value is less than zero.
	ErrInvalidOffsetValueLessThanZero = errors.New("invalid offset value, must be greater than zero")
	// ErrInvalidLimitValueNotANumber expected error when fails parse limit value to int
	ErrInvalidLimitValueNotANumber = errors.New("invalid limit value, must be a number")
	// ErrInvalidLimitValueLessThanZero expected error when limit value is less than zero.
	ErrInvalidLimitValueLessThanZero = errors.New("invalid limit value, must be greater than zero")
)

Functions

This section is empty.

Types

type Decoder

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

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

func NewDecoder

func NewDecoder(params url.Values, opts ...Option) *Decoder

NewDecoder returns a new decoder that reads from params.

func (*Decoder) Decode

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

Decode reads the next Paging-encoded value from params and stores it in the value pointed to by v.

type Option

type Option func(*Decoder)

Option allows to modify the defaults decode values.

func Limit

func Limit(limit int) Option

Limit set the paging limit default.

func MaxAllowedLimit

func MaxAllowedLimit(maxAllowed int) Option

MaxAllowedLimit set the max allowed limit default.

type Paging

type Paging struct {
	MaxAllowedLimit int   `json:"max_allowed_limit"`
	Limit           int   `json:"limit"`
	Offset          int64 `json:"offset"`
	Total           int64 `json:"total,omitempty"`
}

Paging struct allows to do pagination into a collection.

func (Paging) MarshalJSON

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