# README
pagination
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])
}
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
Header adds an http header for pagination using a responsewriter where backwards compatibility is required.
HeaderWithFormatter adds an HTTP header for pagination which uses a custom formatter for generating the URL links.
Index uses limit, offset, and a slice's length to compute start and end indices for said slice.
MaxItemsPerPage is used to prevent DoS attacks against large lists by limiting the items per page to 500.
Parse parses limit and offset from *http.Request with given limits and defaults.