forked from savaki/ddbstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
67 lines (55 loc) · 1.29 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
59
60
61
62
63
64
65
66
67
package ddbstream
import (
"time"
"github.com/aws/aws-sdk-go/service/dynamodbstreams"
)
const (
defaultBatchSize = 100
defaultInterval = 5 * time.Second
)
type Options struct {
batchSize int
debug func(format string, args ...interface{})
pollInterval time.Duration
shardIteratorType string
}
type Option func(*Options)
func WithBatchSize(n int) Option {
return func(o *Options) {
o.batchSize = n
}
}
func WithDebug(fn func(format string, args ...interface{})) Option {
return func(o *Options) {
o.debug = fn
}
}
func WithIteratorType(shardIteratorType string) Option {
return func(o *Options) {
o.shardIteratorType = shardIteratorType
}
}
func WithPollInterval(interval time.Duration) Option {
return func(o *Options) {
o.pollInterval = interval
}
}
func buildOptions(opts ...Option) Options {
options := Options{}
for _, opt := range opts {
opt(&options)
}
if options.batchSize <= 0 || options.batchSize > 1000 {
options.batchSize = defaultBatchSize
}
if options.debug == nil {
options.debug = func(format string, args ...interface{}) {}
}
if options.pollInterval <= 0 {
options.pollInterval = defaultInterval
}
if options.shardIteratorType == "" {
options.shardIteratorType = dynamodbstreams.ShardIteratorTypeLatest
}
return options
}