paginator

package module
v0.0.0-...-efdd128 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2016 License: MIT Imports: 9 Imported by: 2

README

paginator

Paginator for golang

Documentation

Overview

paginator imlementation for golang

Index

Constants

View Source
const (
	DEFAULT_PAGE           = 1
	DEFAULT_PAGE_PARAM     = "page"
	DEFAULT_PER_PAGE       = 10
	DEFAULT_PER_PAGE_PARAM = "limit"

	// context keys
	CONTEXT_ON_REQUEST_REQUEST = 1
)

Variables

View Source
var (
	DEBUG = true
)

Functions

func IsEnabled

func IsEnabled(options []bool) bool

IsEnabled is function that returns value of optional switches in functions

Example:

func (normalize...bool) {
	isset := IsEnabled(normalize)
}

Types

type Factory

type Factory func(from ...interface{}) Paginator

Factory function that returns paging, from can be request of gorm dg

func NewFactory

func NewFactory(options ...Option) Factory

NewFactory returns function that produces instance of Paginator. options control the creation of Paginators. If you provide any compatible `froms` when calling factory, they will be passed to `From` method.

type Option

type Option func(p Paginator, first bool)

Option for paginator factory

func DisablePerPage

func DisablePerPage() Option

func PageParam

func PageParam(param string) Option

OptPageParam sets page param name on factory, if blank value given, it's disabled

func PerPage

func PerPage(limits ...int) Option

LimitChoices sets choices for limit

func PerPageParam

func PerPageParam(param string) Option

OptPerPageParam sets per page param name on factory, if blank value given, it's disabled

type Paginator

type Paginator interface {
	Count(int) Paginator
	GetCount() int

	Page(int) Paginator
	GetPage() int

	PerPage(int) Paginator
	GetPerPage() int

	// Normalize normalizes paginator (runs all options on it)
	Normalize() Paginator

	// return num of pages
	GetNumPages() int

	// read data from request, db
	From(...interface{}) Paginator
	FromDB(DB *gorm.DB, normalize ...bool) Paginator
	//FromJSON([]byte) Paginator
	FromRequest(request *http.Request, normalize ...bool) Paginator
	FromURLValues(values url.Values, normalize ...bool) Paginator

	// signal to be called when `From` with request is called or `FromRequest`
	OnRequest(signals.Receiver, ...string)

	PerPageParam(string) Paginator
	PageParam(string) Paginator

	GetLimitOffset(add ...bool) (int, int)

	// json marshal interface
	MarshalJSON() ([]byte, error)

	UpdateURLValues(values url.Values) Paginator
}

Paginator interface

Jump to

Keyboard shortcuts

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