...

Text file src/github.com/ory/x/pagination/README.md

Documentation: github.com/ory/x/pagination

     1# pagination
     2
     3[![CircleCI](https://circleci.com/gh/ory/pagination.svg?style=shield)](https://circleci.com/gh/ory/pagination)
     4
     5A simple helper for dealing with pagination.
     6
     7```
     8go get github.com/ory/pagination
     9```
    10
    11## Example
    12
    13```go
    14package main
    15
    16import (
    17	"github.com/ory/pagination"
    18    "net/http"
    19    "net/url"
    20    "fmt"
    21)
    22
    23func main() {
    24	u, _ := url.Parse("http://localhost/foo?offset=0&limit=10")
    25    limit, offset := pagination.Parse(&http.Request{URL: u}, 5, 5, 10)
    26
    27    items := []string{"a", "b", "c", "d"}
    28    start, end := pagination.Index(limit, offset, len(items))
    29    fmt.Printf("Got items: %v", items[start:end])
    30}
    31```

View as plain text