pagination

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInvalidPageError

func IsInvalidPageError(err error) bool

Types

type Factory

type Factory struct {
	PageName  string // PageName is a query string name to get current page from query string.
	PerPage   uint64 // PerPage is the number of items per page.
	Shortcuts uint64 // Shortcuts must be odd number
	// contains filtered or unexported fields
}

Factory is an object that can create a Paginator.

func NewFactory

func NewFactory(c echo.Context) *Factory

func (*Factory) Paginator

func (f *Factory) Paginator(count uint64) *Paginator

type InvalidPageError

type InvalidPageError struct {
	CurrentPage uint64
	PagesCount  uint64
}

func (*InvalidPageError) Error

func (e *InvalidPageError) Error() string
type Link struct {
	Url    string `json:"url"`
	Label  string `json:"label"`
	Active bool   `json:"active"`
}

type Paginator

type Paginator struct {
	Path                     string     // Base URL path
	Query                    url.Values // The query parameters to add to all URLs.
	PageName                 string     // The parameter name of the page.
	ItemsCount               uint64     // The number of total items.
	CurrentPage              uint64     // The current page.
	Invalid                  bool       // If the current page is not correct position, it has true.
	PerPage                  uint64     // The number of items to be shown per page.
	PagesCount               uint64     // The number of total pages
	Offset                   uint64     // The offset.
	HasPrevious              bool       // If it has previous page
	PreviousPage             uint64     // The previous page
	HasNext                  bool       // If it has next page
	NextPage                 uint64     // The next page
	NumShortcuts             uint64     // The maximum number of shortcut links.
	ShortcutPages            []uint64   // The array of the shortcut pages
	HasMorePreviousShortcuts bool       // It has more pages before shortcut links
	HasMoreNextShortcuts     bool       // It has more pages after shortcut links
}

func (*Paginator) First

func (pg *Paginator) First() bool

func (*Paginator) FirstPageUrl

func (pg *Paginator) FirstPageUrl() string

func (*Paginator) From

func (pg *Paginator) From() uint64

func (*Paginator) LastPageUrl

func (pg *Paginator) LastPageUrl() string
func (pg *Paginator) Links() []*Link

func (*Paginator) NextPageUrl

func (pg *Paginator) NextPageUrl() string

func (*Paginator) PreviousPageUrl

func (pg *Paginator) PreviousPageUrl() string

func (*Paginator) SprintIfNotFirst

func (pg *Paginator) SprintIfNotFirst(text string) string

func (*Paginator) To

func (pg *Paginator) To() uint64

func (*Paginator) Url

func (pg *Paginator) Url(page uint64) string

Url returns a URL for a given page number.

Jump to

Keyboard shortcuts

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