pagination.go 726 B

1234567891011121314151617181920212223242526272829
  1. package common
  2. type Pagination struct {
  3. Records []interface{} `json:"records"`
  4. Current int `json:"current" ` // 页码:默认第 1 页
  5. PageSize int `json:"size" `
  6. Total int64 `json:"total"`
  7. }
  8. func NewPagination() Pagination {
  9. return Pagination{
  10. Current: 1, // 默认第 1 页
  11. PageSize: 10, // 默认每页 10 条
  12. }
  13. }
  14. // Records 序列化 转化成 []interface{}
  15. func (p *Pagination) RecordsToInterface(records []interface{}) {
  16. p.Records = records
  17. }
  18. func BuildPagination(records []interface{}, currentPage int, pageSize int, totalCount int64) Pagination {
  19. return Pagination{
  20. Records: records,
  21. Current: currentPage,
  22. PageSize: pageSize,
  23. Total: totalCount,
  24. }
  25. }