refactor: phase 2 structural alignment — reports, importer, nodecli, pagination
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package store
|
||||
|
||||
import "strconv"
|
||||
|
||||
// PaginateOffset returns a page from a pre-sorted slice using numeric string cursors (same scheme as ListRevisions).
|
||||
func PaginateOffset[T any](all []T, cursor string, limit int) (page []T, nextCursor string, hasMore bool) {
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
off := 0
|
||||
if cursor != "" {
|
||||
if n, err := strconv.Atoi(cursor); err == nil && n >= 0 {
|
||||
off = n
|
||||
}
|
||||
}
|
||||
if off > len(all) {
|
||||
off = len(all)
|
||||
}
|
||||
end := off + limit
|
||||
if end > len(all) {
|
||||
end = len(all)
|
||||
}
|
||||
page = all[off:end]
|
||||
if end < len(all) {
|
||||
nextCursor = strconv.Itoa(end)
|
||||
hasMore = true
|
||||
}
|
||||
return page, nextCursor, hasMore
|
||||
}
|
||||
Reference in New Issue
Block a user