-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.go
More file actions
86 lines (66 loc) · 1.78 KB
/
Copy pathconfig.go
File metadata and controls
86 lines (66 loc) · 1.78 KB
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
package ddb
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
const (
defaultAwsRegion = "us-west-1"
defaultTotalSegments = 50
)
// Config is wrapper around the configuration variables
type Config struct {
// Svc the dynamodb connection
Svc *dynamodb.DynamoDB
// AwsRegion is the region the database is in. Defaults to us-west-1
AwsRegion string
// TableName is name of table to scan
TableName string
// SegmentOffset determines where to start indexing from
SegmentOffset int
// SegmentCount deterines how big a segment is
SegmentCount int
// TotalSegments determines the global amount of concurrency this will use
TotalSegments int
// Checkpoint
Checkpoint *Checkpoint
// CheckpointTableName is the name of checkpont table
CheckpointTableName string
// CheckpointNamespace is the unique namespace for checkpoints. This must be unique so
// checkpoints so differnt scripts can maintain their own checkpoints.
CheckpointNamespace string
// Limit is the number of records to return during scan
Limit int64
}
// defaults for configuration.
func (c *Config) setDefaults() {
if c.AwsRegion == "" {
c.AwsRegion = defaultAwsRegion
}
if c.TableName == "" {
log.Fatal("TableName required as config var")
}
if c.TotalSegments == 0 {
c.TotalSegments = defaultTotalSegments
}
if c.SegmentCount == 0 {
c.SegmentCount = c.TotalSegments
}
if c.Limit == 0 {
c.Limit = 1000
}
if c.Svc == nil {
c.Svc = dynamodb.New(
session.New(),
aws.NewConfig().WithRegion(c.AwsRegion),
)
}
if c.CheckpointTableName != "" && c.CheckpointNamespace != "" {
c.Checkpoint = &Checkpoint{
TableName: c.CheckpointTableName,
Namespace: c.CheckpointNamespace,
Svc: c.Svc,
}
}
}