-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_user.go
134 lines (116 loc) · 2.96 KB
/
type_user.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package ghid
import (
"fmt"
"strconv"
"github.com/vmihailenco/msgpack/v5"
)
func init() {
RegisterDecodeV1(TypeUser, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode user id: %w", err)
}
return UserKey{ID: id}, nil
})
RegisterDecodeV2(TypeUser, func(key msgpack.RawMessage) (KeyV2, error) {
id, err := decodeV2Uint(TypeUser, 0, key)
if err != nil {
return nil, err
}
return UserKey{ID: id}, nil
})
RegisterDecodeV1(TypeBot, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode bot id: %w", err)
}
return BotKey{ID: id}, nil
})
RegisterDecodeV2(TypeBot, func(key msgpack.RawMessage) (KeyV2, error) {
id, err := decodeV2Uint(TypeBot, 0, key)
if err != nil {
return nil, err
}
return BotKey{ID: id}, nil
})
RegisterDecodeV1(TypeMannequin, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode mannequin id: %w", err)
}
return MannequinKey{ID: id}, nil
})
RegisterDecodeV2(TypeMannequin, func(key msgpack.RawMessage) (KeyV2, error) {
id, err := decodeV2Uint(TypeMannequin, 0, key)
if err != nil {
return nil, err
}
return MannequinKey{ID: id}, nil
})
}
var (
_ KeyV1 = UserKey{}
_ KeyV2 = UserKey{}
)
// UserKey is a unique key for User nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#user.
type UserKey struct {
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r UserKey) Type() string {
return TypeUser
}
// KeyV1 implements KeyV1.
func (r UserKey) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// KeyV2 implements KeyV2.
func (r UserKey) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.ID)})
}
var (
_ KeyV1 = BotKey{}
_ KeyV2 = BotKey{}
)
// BotKey is a unique key for Bot nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#bot.
type BotKey struct {
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r BotKey) Type() string {
return TypeBot
}
// KeyV1 implements KeyV1.
func (r BotKey) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// KeyV2 implements KeyV2.
func (r BotKey) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.ID)})
}
var (
_ KeyV1 = MannequinKey{}
_ KeyV2 = MannequinKey{}
)
// MannequinKey is a unique key Mannequin Bot nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#mannequin.
type MannequinKey struct {
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r MannequinKey) Type() string {
return TypeMannequin
}
// KeyV1 implements KeyV1.
func (r MannequinKey) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// KeyV2 implements KeyV2.
func (r MannequinKey) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.ID)})
}