Categorygithub.com/ory/pagination
modulepackage
0.0.1
Repository: https://github.com/ory/pagination.git
Documentation: pkg.go.dev

# 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])
}

# Functions

Index uses limit, offset, and a slice's length to compute start and end indices for said slice.
Parse parses limit and offset from *http.Request with given limits and defaults.