/
options.go
55 lines (47 loc) 路 1.36 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
package delegatedrouting
import "time"
const (
defaultSnapshotMaxChunkSize = 1_000_000
defaultPageSize = 20_000
defaultFlushFrequency = 10 * time.Minute
)
type Options struct {
// SnapshotMaxChunkSize defines a size of a chunk that CID snapshot is
// going to be split into before stored in the datastore. Needed as leveldb
// can't handle binary payloads above a certain threshold
SnapshotMaxChunkSize int
// PageSize defines a maximum number of results that can be returned by a
// query during datastore initialisation
PageSize int
// AdFlushFrequency defines a frequency of a flush operation that is going
// to be performed on the current chunk. In other words a non empty current
// chunk will be converted to an ad and published.
AdFlushFrequency time.Duration
}
type Option func(*Options)
func WithSnapshotMaxChunkSize(i int) Option {
return func(o *Options) {
o.SnapshotMaxChunkSize = i
}
}
func WithPageSize(i int) Option {
return func(o *Options) {
o.PageSize = i
}
}
func WithAdFlushFrequency(d time.Duration) Option {
return func(o *Options) {
o.AdFlushFrequency = d
}
}
func ApplyOptions(opt ...Option) Options {
opts := Options{
SnapshotMaxChunkSize: defaultSnapshotMaxChunkSize,
PageSize: defaultPageSize,
AdFlushFrequency: defaultFlushFrequency,
}
for _, o := range opt {
o(&opts)
}
return opts
}