func main() {
PageRange(34, 10, func(page, startIndex, endIndex int) {
fmt.Println(page, startIndex, endIndex)
})
}
func PageRange(count int, pageSize int, f func(page, startIndex, endIndex int)) {
// 整页
pageMax := count / pageSize // 最大页数
for page := 0; page < pageMax; page++ {
startIndex := page * pageSize
f(page, startIndex, startIndex+pageSize-1)
}
// 残叶
if n := count % pageSize; n > 0 {
startIndex := pageMax * pageSize
f(pageMax, startIndex, startIndex+n-1)
}
return
}