lab2: fix review round 2 — cache versioning, UUID normalization, cursor validation, ready deps
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-10 07:46:39 +03:00
parent 40f260612f
commit 6e3515d71b
8 changed files with 160 additions and 57 deletions
+12 -3
View File
@@ -4,27 +4,36 @@ import (
"encoding/base64"
"strings"
"time"
"github.com/google/uuid"
)
// encodeCursor кодирует (scope, created_at, id) в base64.
func encodeCursor(scope string, createdAt time.Time, id string) string {
raw := scope + "|" + createdAt.UTC().Format(time.RFC3339Nano) + "|" + id
return base64.RawURLEncoding.EncodeToString([]byte(raw))
}
// decodeCursor декодирует и проверяет scope.
func decodeCursor(cursor, expectedScope string) (time.Time, string, error) {
raw, err := base64.RawURLEncoding.DecodeString(cursor)
if err != nil {
return time.Time{}, "", ErrInvalidInput
}
parts := strings.SplitN(string(raw), "|", 3)
if len(parts) != 3 || parts[0] != expectedScope {
if len(parts) != 3 {
return time.Time{}, "", ErrInvalidInput
}
if _, err := uuid.Parse(parts[0]); err != nil {
return time.Time{}, "", ErrInvalidInput
}
if parts[0] != expectedScope {
return time.Time{}, "", ErrInvalidInput
}
t, err := time.Parse(time.RFC3339Nano, parts[1])
if err != nil {
return time.Time{}, "", ErrInvalidInput
}
if _, err := uuid.Parse(parts[2]); err != nil {
return time.Time{}, "", ErrInvalidInput
}
return t, parts[2], nil
}