page_utils.go 666 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package page
  2. import "math"
  3. type PageInfo struct {
  4. LatestId int64
  5. Current int
  6. PageSize int
  7. Total int64
  8. }
  9. type PageResult struct {
  10. Page Page
  11. Data interface{}
  12. }
  13. type Page struct {
  14. LatestId int64 `json:"latestId,omitempty"`
  15. Current int `json:"current"`
  16. PageSize int `json:"pageSize"`
  17. Total int64 `json:"total"`
  18. TotalPage int `json:"totalPage"`
  19. }
  20. func StartIndex(page, pagesize int) int {
  21. if page > 1 {
  22. return (page - 1) * pagesize
  23. }
  24. return 0
  25. }
  26. func TotalPages(total int64, pagesize int) int {
  27. return int(math.Ceil(float64(total) / float64(pagesize)))
  28. }
  29. func (p *PageInfo) Reset() {
  30. p.Current = 0
  31. p.PageSize = 0
  32. p.LatestId = 0
  33. }