Files
mtusi2026lab2/src/internal/store/cursor.go
T
Sh1pYe 41e8d67a1a
Application (lab2) / app (pull_request) Failing after 36s
Skeleton contracts / contracts (pull_request) Failing after 29s
Lab2- оценка 5
2026-10-08 14:14:20 +03:00

34 lines
629 B
Go

package store
import (
"encoding/base64"
"encoding/json"
"time"
)
type Cursor struct {
Scope string `json:"s"`
TS time.Time `json:"t"`
ID string `json:"i"`
}
func EncodeCursor(c Cursor) string {
b, _ := json.Marshal(c)
return base64.RawURLEncoding.EncodeToString(b)
}
func DecodeCursor(s string) (Cursor, error) {
var c Cursor
b, err := base64.RawURLEncoding.DecodeString(s)
if err != nil {
return c, ErrInvalidCursor
}
if err := json.Unmarshal(b, &c); err != nil {
return c, ErrInvalidCursor
}
if c.Scope == "" || c.ID == "" || c.TS.IsZero() {
return c, ErrInvalidCursor
}
return c, nil
}