forked from Permify/permify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
70 lines (60 loc) · 1.44 KB
/
token.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package token
type EncodedSnapToken interface {
// String returns the string representation of the token.
String() string
// Decode decodes the token from a string
Decode() (SnapToken, error)
}
type SnapToken interface {
// Encode encodes the token to a string.
Encode() EncodedSnapToken
// Eg snapshot is equal to given snapshot
Eg(token SnapToken) bool
// Gt snapshot is greater than given snapshot
Gt(token SnapToken) bool
// Lt snapshot is less than given snapshot
Lt(token SnapToken) bool
}
type (
NoopToken struct {
Value string
}
NoopEncodedToken struct {
Value string
}
)
// NewNoopToken - Creates a new noop snapshot token
func NewNoopToken() SnapToken {
return NoopToken{
Value: "noop",
}
}
// Encode - encodes the token to a string
func (t NoopToken) Encode() EncodedSnapToken {
return NoopEncodedToken{
Value: "noop",
}
}
// Eg - Snapshot is equal to given snapshot
func (t NoopToken) Eg(token SnapToken) bool {
_, ok := token.(NoopToken)
return ok
}
// Gt - Snapshot is greater than given snapshot
func (t NoopToken) Gt(token SnapToken) bool {
return false
}
// Lt - Snapshot is less than given snapshot
func (t NoopToken) Lt(token SnapToken) bool {
return false
}
// Decode - Decodes the token from a string
func (t NoopEncodedToken) Decode() (SnapToken, error) {
return NoopToken{
Value: "noop",
}, nil
}
// Decode - Decodes the token from a string
func (t NoopEncodedToken) String() string {
return t.Value
}