-
Notifications
You must be signed in to change notification settings - Fork 123
/
pagination.go
48 lines (41 loc) · 1.04 KB
/
pagination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package utils
import (
"encoding/base64"
"github.com/Permify/permify/pkg/database"
)
type (
// ContinuousToken - Structure for continuous token
ContinuousToken struct {
Value string
}
// EncodedContinuousToken - Structure for encoded continuous token
EncodedContinuousToken struct {
Value string
}
)
// NewContinuousToken - Creates a new continuous token
func NewContinuousToken(value string) database.ContinuousToken {
return &ContinuousToken{
Value: value,
}
}
// Encode - Encodes the token to a string
func (t ContinuousToken) Encode() database.EncodedContinuousToken {
return EncodedContinuousToken{
Value: base64.StdEncoding.EncodeToString([]byte(t.Value)),
}
}
// Decode decodes the token from a string
func (t EncodedContinuousToken) Decode() (database.ContinuousToken, error) {
b, err := base64.StdEncoding.DecodeString(t.Value)
if err != nil {
return nil, err
}
return ContinuousToken{
Value: string(b),
}, nil
}
// Decode decodes the token from a string
func (t EncodedContinuousToken) String() string {
return t.Value
}