fix: update GetPage to check for empty items slice

Refactor the GetPage function to check for an empty slice of items 
instead of a nil pointer. Update tests to cover cases for nil and 
empty slices, ensuring consistent behavior and improved clarity.
This commit is contained in:
2025-06-16 09:09:04 +02:00
parent 704b755c4c
commit 8e8bdac22c
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ func EncodeCursor(cursor string) string {
}
func GetPage[T any](items []T, first *int, after *string, last *int, before *string, max int, fn func(T) string) ([]T, PageInfo) {
if items == nil {
if len(items) == 0 {
return nil, PageInfo{}
}
tmp := min(max, len(items))