blob: 4d415875f31f9453611fc882dc00ace88f16240c (
plain)
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
|
package pagination
type Pagination struct {
total uint64
From int
Size,
Current,
Prev,
Next int
Needed bool
}
func New(page int, pageSize int) *Pagination {
return &Pagination{
Current: page,
From: (page - 1) * pageSize,
Size: pageSize,
}
}
func (p *Pagination) SetResults(total uint64) {
p.total = total
p.Needed = p.total > uint64(p.Size)
if uint64(p.Current*p.Size) <= p.total {
p.Next = p.Current + 1
p.Prev = p.Current - 1
}
}
|