refactor: version cursor - update payload

This commit is contained in:
Dawid Wysokiński 2024-02-06 07:14:19 +01:00
parent 186c8d6765
commit 74c5d842ce
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
2 changed files with 11 additions and 3 deletions

View File

@ -241,6 +241,7 @@ var ErrNil error = simpleError{
code: "nil",
}
// ErrInvalidCursor is an error that is returned when a cursor can't be decoded (e.g. is malformed).
var ErrInvalidCursor error = simpleError{
msg: "invalid cursor",
typ: ErrorTypeIncorrectInput,

View File

@ -4,6 +4,7 @@ import (
"encoding/base64"
"fmt"
"net/url"
"strings"
)
const (
@ -140,13 +141,19 @@ func decodeVersionCursor(encoded string) (VersionCursor, error) {
return VersionCursor{}, err
}
decoded, err := base64.StdEncoding.DecodeString(encoded)
decodedBytes, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return VersionCursor{}, ErrInvalidCursor
}
decoded := string(decodedBytes)
code, ok := strings.CutPrefix(decoded, "code=")
if !ok {
return VersionCursor{}, ErrInvalidCursor
}
vc, err := NewVersionCursor(NullString{
Value: string(decoded),
Value: code,
Valid: true,
})
if err != nil {
@ -169,7 +176,7 @@ func (vc VersionCursor) Encode() string {
return ""
}
return base64.StdEncoding.EncodeToString([]byte(vc.code.Value))
return base64.StdEncoding.EncodeToString([]byte("code=" + vc.code.Value))
}
type ListVersionsParams struct {