Passed
Pull Request — master (#1470)
by Tolga
02:39
created

internal/storage/context/utils/pagination.go   A

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 23
dl 0
loc 47
rs 10
c 0
b 0
f 0

4 Methods

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