You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
591 B
23 lines
591 B
package methods
|
|
|
|
import (
|
|
"wss-pool/pkg/model/stock"
|
|
)
|
|
|
|
// Paginate 函数根据 pageNumber 和 pageSize 对原始数据进行分页
|
|
func Paginate(data []stock.StockShare, pageNumber int, pageSize int) []stock.StockShare {
|
|
// 获取原始数据长度
|
|
dataLen := len(data)
|
|
// 计算分页开始和结束的索引
|
|
startIndex := (pageNumber - 1) * pageSize
|
|
endIndex := startIndex + pageSize
|
|
// 处理边界情况
|
|
if startIndex > dataLen {
|
|
return []stock.StockShare{}
|
|
}
|
|
if endIndex > dataLen {
|
|
endIndex = dataLen
|
|
}
|
|
// 返回分页后的切片
|
|
return data[startIndex:endIndex]
|
|
}
|
|
|