forked from mtusi2026/mtusi2026lab2
fixed a bug in pagination
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user