-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_repo.go
62 lines (52 loc) · 1.33 KB
/
type_repo.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
package ghid
import (
"fmt"
"strconv"
"github.com/vmihailenco/msgpack/v5"
)
func init() {
RegisterDecodeV1(TypeRepository, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode repo id: %w", err)
}
return RepoKey{ID: RepoID(id)}, nil
})
RegisterDecodeV2(TypeRepository, func(key msgpack.RawMessage) (KeyV2, error) {
id, err := decodeV2Uint(TypeRepository, 0, key)
if err != nil {
return nil, err
}
return RepoKey{ID: RepoID(id)}, nil
})
}
// RepoID corresponds to databaseId field of the Repository node.
//
// See https://docs.github.com/en/graphql/reference/objects#repository.
type RepoID uint64
var (
_ KeyV1 = RepoKey{}
_ KeyV2 = RepoKey{}
)
// RepoKey is a unique key for Repository nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#repository.
type RepoKey struct {
ID RepoID // corresponds to databaseId
}
// Type implements Key.
func (r RepoKey) Type() string {
return TypeRepository
}
// GetRepoID implements KeyWithRepo.
func (r RepoKey) GetRepoID() RepoID {
return r.ID
}
// KeyV1 implements KeyV1.
func (r RepoKey) KeyV1() string {
return strconv.FormatUint(uint64(r.ID), 10)
}
// KeyV2 implements KeyV2.
func (r RepoKey) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.ID)})
}