Skip to content

Commit 9885811

Browse files
committed
changes
1 parent da6a0dd commit 9885811

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pagination.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ func PaginateDataWithContext(ctx context.Context, db *sql.DB, paginator models.P
125125
// calculate offset
126126
lastPage := CalculateTotalPages(total, perPage)
127127

128+
if page < 1 {
129+
130+
page = 1
131+
}
132+
128133
currentPage := page - 1
134+
129135
offset := 0
130136

131137
if currentPage > 0 {
@@ -143,6 +149,11 @@ func PaginateDataWithContext(ctx context.Context, db *sql.DB, paginator models.P
143149
offset = total - (currentPage * perPage)
144150
}
145151

152+
if offset < 0 {
153+
154+
offset = currentPage * perPage
155+
}
156+
146157
from := offset + 1
147158
currentPage++
148159

0 commit comments

Comments
 (0)