warehouse/utils/pagination.go

15 lines
272 B
Go
Raw Normal View History

2024-11-17 22:08:06 +01:00
package utils
// Paginate returns a slicle with offset & limit
func Paginate[T any](items []T, offset, limit int) []T {
if len(items) <= offset {
return []T{}
}
if limit > len(items)-offset {
limit = len(items) - offset
}
return items[offset : offset+limit]
}