/
paginator.go
77 lines (66 loc) · 1.5 KB
/
paginator.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
70
71
72
73
74
75
76
77
package goreq
import (
"github.com/dimonrus/gorest"
"github.com/dimonrus/porterr"
)
// IPaginator interface
type IPaginator interface {
// GetPage get current page
GetPage() int
// SetPage set current page
SetPage(page int)
// GetLimit get limit
GetLimit() int
// SetLimit set limit
SetLimit(limit int)
// GetParallelCount get parallel request count
GetParallelCount() int
// SetParallelCount set parallel request count
SetParallelCount(count int)
}
// Paginator Base paginator struct
// Inject the struct into your request forms
type Paginator struct {
// Page of pagination
Page int `json:"page"`
// Limit for pagination
Limit int `json:"limit"`
// Parallel request
ParallelCount int `json:"parallelCount"`
}
// GetPage get current page
func (p *Paginator) GetPage() int {
return p.Page
}
// SetPage set current page
func (p *Paginator) SetPage(page int) {
p.Page = page
return
}
// GetLimit get limit
func (p *Paginator) GetLimit() int {
return p.Limit
}
// SetLimit set limit
func (p *Paginator) SetLimit(limit int) {
p.Limit = limit
return
}
// GetParallelCount get count of max parallel requests
func (p *Paginator) GetParallelCount() int {
return p.ParallelCount
}
// SetParallelCount set max number of parallel request
func (p *Paginator) SetParallelCount(count int) {
p.ParallelCount = count
return
}
// PaginatorResponse Response from API
type PaginatorResponse[T any] struct {
// List of elements
Items []T
// Meta information
Meta gorest.Meta
// Error
Error porterr.IError
}