123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package pagination
- type Pagination interface {
- OffsetLimit() *offsetLimit
- Page() *page
- }
- type page struct {
- Now uint32
- Size uint32
- }
- type offsetLimit struct {
- Offset uint32
- Limit uint32
- }
- type custom struct {
- Now uint32
- Size uint32
- }
- func (p *custom) OffsetLimit() *offsetLimit {
- pageNow := p.Now
- if pageNow > 1 {
- pageNow = pageNow - 1
- } else {
- pageNow = 0
- }
- return &offsetLimit{
- Offset: pageNow * p.Size,
- Limit: p.Size,
- }
- }
- func (p *custom) Page() *page {
- return &page{
- Now: p.Now,
- Size: p.Size,
- }
- }
- func New(now, size uint32) Pagination {
- return &custom{
- Now: now,
- Size: size,
- }
- }
|