pagination

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: Apache-2.0 Imports: 2 Imported by: 17

README

pagination

CircleCI

A simple helper for dealing with pagination.

go get github.com/ory/pagination

Example

package main

import (
	"github.com/ory/pagination"
    "net/http"
    "net/url"
    "fmt"
)

func main() {
	u, _ := url.Parse("http://localhost/foo?offset=0&limit=10")
    limit, offset := pagination.Parse(&http.Request{URL: u}, 5, 5, 10)

    items := []string{"a", "b", "c", "d"}
    start, end := pagination.Index(limit, offset, len(items))
    fmt.Printf("Got items: %v", items[start:end])
}

Documentation

Overview

Package pagination provides helpers for dealing with pagination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Index

func Index(limit, offset, length int) (start, end int)

Index uses limit, offset, and a slice's length to compute start and end indices for said slice.

func Parse

func Parse(r *http.Request, defaultLimit, defaultOffset, maxLimit int) (int, int)

Parse parses limit and offset from *http.Request with given limits and defaults.

Types

This section is empty.

Jump to

Keyboard shortcuts

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