fixed a bug in pagination

This commit is contained in:
Нурлыгаянова Екатерина
2026-10-29 14:34:10 +03:00
parent 8bb0350f6d
commit 98ffd9ff45
2 changed files with 49 additions and 0 deletions
+12
View File
@@ -4,6 +4,8 @@ import (
"encoding/base64"
"encoding/json"
"time"
"github.com/google/uuid"
)
type Page[T any] struct {
@@ -51,5 +53,15 @@ func DecodeCursor(s string) (Cursor, error) {
if err := json.Unmarshal(raw, &c); err != nil {
return Cursor{}, ErrInvalidArgument
}
if c.CreatedAt.IsZero() || c.Scope == "" {
return Cursor{}, ErrInvalidArgument
}
if _, err := uuid.Parse(c.ID); err != nil || len(c.ID) != 36 {
return Cursor{}, ErrInvalidArgument
}
if EncodeCursor(c) != s {
return Cursor{}, ErrInvalidArgument
}
return c, nil
}