-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
pagination.go
69 lines (58 loc) · 1.76 KB
/
pagination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package x
import (
"net/http"
"net/url"
"github.com/ory/x/pagination/tokenpagination"
)
// swagger:model paginationHeaders
type PaginationHeaders struct {
// The link header contains pagination links.
//
// For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
//
// in: header
Link string `json:"link"`
// The total number of clients.
//
// in: header
XTotalCount string `json:"x-total-count"`
}
// swagger:model pagination
type PaginationParams struct {
// Items per page
//
// This is the number of items per page to return.
// For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
//
// required: false
// in: query
// default: 250
// min: 1
// max: 1000
PageSize int `json:"page_size"`
// Next Page Token
//
// The next page token.
// For details on pagination please head over to the [pagination documentation](https://www.ory.sh/docs/ecosystem/api-design#pagination).
//
// required: false
// in: query
// default: 1
// min: 1
PageToken string `json:"page_token"`
}
const paginationMaxItems = 1000
const paginationDefaultItems = 250
var paginator = &tokenpagination.TokenPaginator{
MaxItems: paginationMaxItems,
DefaultItems: paginationDefaultItems,
}
// ParsePagination parses limit and page from *http.Request with given limits and defaults.
func ParsePagination(r *http.Request) (page, itemsPerPage int) {
return paginator.ParsePagination(r)
}
func PaginationHeader(w http.ResponseWriter, u *url.URL, total int64, page, itemsPerPage int) {
tokenpagination.PaginationHeader(w, u, total, page, itemsPerPage)
}