示例代码
func paginateArray(arr []interface{}, page, pageSize int) []interface{} {
if page < 1 {page = 1}
if pageSize < 10 {pageSize = 10}
from := (page - 1) * pageSize
to := from + pageSize
if to > len(arr) {to = len(arr)
}
return arr[from:to]
}
正文完