internal/pagination/pagination.go (view raw)
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 | package pagination
import "alin.ovh/searchix/internal/config"
type Pagination struct {
total uint64
From int
Size,
Current,
Prev,
Next int
Needed bool
CanShowAll bool
}
func New(page int, pageSize int) *Pagination {
return &Pagination{
Current: page,
From: (page - 1) * pageSize,
Size: pageSize,
Needed: page > 1,
}
}
func (p *Pagination) SetResults(total uint64) {
p.total = total
p.Needed = p.Needed || (total > uint64(p.Size))
p.CanShowAll = p.Needed && total < config.MaxResultsShowAll
if p.Current > 1 {
p.Prev = p.Current - 1
}
if uint64(p.Current*p.Size) <= p.total {
p.Next = p.Current + 1
}
}
|