diff --git a/handlers/build/queue.go b/handlers/build/queue.go index 4b33886..d3917c1 100644 --- a/handlers/build/queue.go +++ b/handlers/build/queue.go @@ -49,7 +49,17 @@ func Queue(c *fiber.Ctx) error { return finalReturn[i].Source.Name < finalReturn[j].Source.Name }) - result := finalReturn[adjustedPageNum*pageSize : (adjustedPageNum+1)*pageSize] + var result []domain.BuildQueueItem + startIndex := adjustedPageNum * pageSize + endIndex := (adjustedPageNum + 1) * pageSize + if startIndex >= len(finalReturn) { + result = []domain.BuildQueueItem{} + } else { + if endIndex > len(finalReturn) { + endIndex = len(finalReturn) + } + result = finalReturn[startIndex:endIndex] + } response := QueueResponse{ Total: len(finalReturn), diff --git a/handlers/packages/packages.go b/handlers/packages/packages.go index 1ee2d1b..17966d2 100644 --- a/handlers/packages/packages.go +++ b/handlers/packages/packages.go @@ -52,7 +52,17 @@ func Packages(c *fiber.Ctx) error { return finalReturn[i].Name < finalReturn[j].Name }) - result := finalReturn[adjustedPageNum*pageSize : (adjustedPageNum+1)*pageSize] + var result []domain.SourcePackage + startIndex := adjustedPageNum * pageSize + endIndex := (adjustedPageNum + 1) * pageSize + if startIndex >= len(finalReturn) { + result = []domain.SourcePackage{} + } else { + if endIndex > len(finalReturn) { + endIndex = len(finalReturn) + } + result = finalReturn[startIndex:endIndex] + } response := PackagesResponse{ Total: len(finalReturn),