-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination.go
50 lines (41 loc) · 1.21 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
package deviantart
// OffsetParams params for offset-based pagination.
type OffsetParams struct {
// The pagination offset.
Offset uint32 `url:"offset,omitempty"`
// The pagination limit.
Limit uint32 `url:"limit,omitempty"`
}
type OffsetResponse[T any] struct {
Results []T `json:"results"`
HasMore bool `json:"has_more"`
NextOffset uint32 `json:"next_offset,omitempty"`
// This field is used in some endpoints with a query parameter.
// TODO: Use separate struct and API method (?).
EstimatedTotal uint32 `json:"estimated_total,omitempty"`
}
func (o *OffsetResponse[T]) Next() *OffsetParams {
// TODO: Set a limit.
return &OffsetParams{
Offset: o.NextOffset,
}
}
// CursorParams params for cursor-based pagination.
type CursorParams struct {
Cursor string `url:"cursor,omitempty"`
}
type CursorResponse[T any] struct {
Results []T `json:"results"`
HasMore bool `json:"has_more"`
NextCursor string `json:"next_cursor"`
PrevCursor string `json:"prev_cursor"`
}
func (c *CursorResponse[T]) Next() *CursorParams {
return &CursorParams{
Cursor: c.NextCursor,
}
}
// singleResponse represents response without pagination.
type singleResponse[T any] struct {
Results []T `json:"results"`
}