go-paginator: github.com/phonkee/go-paginator Index | Files

package paginator

import "github.com/phonkee/go-paginator"

paginator imlementation for golang

Index

Package Files

defaults.go factory.go options.go paginator.go utils.go

Constants

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

var (
    DEBUG = true
)

func IsEnabled Uses

func IsEnabled(options []bool) bool

IsEnabled is function that returns value of optional switches in functions

Example:

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

type Factory Uses

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

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

func NewFactory Uses

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 Uses

type Option func(p Paginator, first bool)

Option for paginator factory

func DisablePerPage Uses

func DisablePerPage() Option

func PageParam Uses

func PageParam(param string) Option

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

func PerPage Uses

func PerPage(limits ...int) Option

LimitChoices sets choices for limit

func PerPageParam Uses

func PerPageParam(param string) Option

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

type Paginator Uses

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

Package paginator imports 9 packages (graph) and is imported by 2 packages. Updated 2016-11-25. Refresh now. Tools for package owners.