package common type Pagination struct { Records []interface{} `json:"records"` Current int `json:"current" ` // 页码:默认第 1 页 PageSize int `json:"size" ` Total int64 `json:"total"` } func NewPagination() Pagination { return Pagination{ Current: 1, // 默认第 1 页 PageSize: 10, // 默认每页 10 条 } } // Records 序列化 转化成 []interface{} func (p *Pagination) RecordsToInterface(records []interface{}) { p.Records = records } func BuildPagination(records []interface{}, currentPage int, pageSize int, totalCount int64) Pagination { return Pagination{ Records: records, Current: currentPage, PageSize: pageSize, Total: totalCount, } }