12345678910111213141516171819202122232425262728293031323334353637383940 |
- package page
- import "math"
- type PageInfo struct {
- LatestId int64
- Current int
- PageSize int
- Total int64
- TimeStamp int64
- }
- type PageResult struct {
- Page Page
- Data interface{}
- }
- type Page struct {
- LatestId int64 `json:"latestId,omitempty"`
- Current int `json:"current"`
- PageSize int `json:"pageSize"`
- Total int64 `json:"total"`
- Range string `json:"range"`
- TotalPage int `json:"totalPage"`
- TimeStamp int64 `json:"timeStamp"`
- }
- func StartIndex(page, pagesize int) int {
- if page > 1 {
- return (page - 1) * pagesize
- }
- return 0
- }
- func TotalPages(total int64, pagesize int) int {
- return int(math.Ceil(float64(total) / float64(pagesize)))
- }
- func (p *PageInfo) Reset() {
- p.Current = 0
- p.PageSize = 0
- p.LatestId = 0
- }
|