-
Notifications
You must be signed in to change notification settings - Fork 65
/
options.go
58 lines (49 loc) · 1.54 KB
/
options.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
package service
import (
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/go-threads/crypto/symmetric"
)
// KeyOptions defines options for keys when creating / adding a thread.
type KeyOptions struct {
FollowKey *symmetric.Key
ReadKey *symmetric.Key
LogKey crypto.Key
}
// KeyOption specifies encryption keys.
type KeyOption func(*KeyOptions)
// FollowKey allows thread record traversal.
func FollowKey(key *symmetric.Key) KeyOption {
return func(args *KeyOptions) {
args.FollowKey = key
}
}
// ReadKey allows for thread record decryption.
func ReadKey(key *symmetric.Key) KeyOption {
return func(args *KeyOptions) {
args.ReadKey = key
}
}
// LogKey defines the public or private key used to write a log records.
// If this is just a public key, the service itself won't be able to create records.
// In other words, all records must pre-created and added with AddRecord.
// If no log key is provided, one will be created internally.
func LogKey(key crypto.Key) KeyOption {
return func(args *KeyOptions) {
args.LogKey = key
}
}
// SubOptions defines options for a thread subscription.
type SubOptions struct {
ThreadIDs thread.IDSlice
}
// SubOption is a thread subscription option.
type SubOption func(*SubOptions)
// ThreadID restricts the subscription to the given thread.
// Use this option multiple times to build up a list of threads
// to subscribe to.
func ThreadID(id thread.ID) SubOption {
return func(args *SubOptions) {
args.ThreadIDs = append(args.ThreadIDs, id)
}
}