-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
49 lines (37 loc) · 1.25 KB
/
keys.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
package played
import (
"fmt"
"github.com/apple/foundationdb/bindings/go/src/fdb"
"github.com/apple/foundationdb/bindings/go/src/fdb/tuple"
"golang.org/x/xerrors"
)
func (s *Server) fmtPlayedUserRange(user string) fdb.KeyRange {
pre, _ := fdb.PrefixRange(s.subs.Played.Pack(tuple.Tuple{user}))
return pre
}
func (s *Server) fmtPlayedUserGame(user, game string) fdb.Key {
return s.subs.Played.Pack(tuple.Tuple{user, game})
}
func (s *Server) unpackPlayed(k fdb.Key) (user string, game string, err error) {
tup, err := s.subs.Played.Unpack(k)
if err != nil {
return "", "", xerrors.Errorf("failed to unpack played key: %w", err)
}
if len(tup) != 2 {
return "", "", xerrors.Errorf("unknown played key length. expected 2, got %v", len(tup))
}
return tup[0].(string), tup[1].(string), nil
}
func (s *Server) fmtFirstSeenKey(user string) fdb.Key {
return s.subs.FirstSeen.Pack(tuple.Tuple{user})
}
func (s *Server) fmtLastUpdatedKey(user string) fdb.Key {
return s.subs.LastUpdated.Pack(tuple.Tuple{user})
}
func (s *Server) fmtCurrentGameKey(user string) fdb.Key {
return s.subs.Current.Pack(tuple.Tuple{user})
}
func fmtWhitelistKey(user string) string {
return fmt.Sprintf("played:whitelist:%s", user)
}
const whitelistPrefix = "played:whitelist:*"