/
config.go
60 lines (51 loc) · 1.45 KB
/
config.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
package main
import (
"log"
"os"
"time"
"github.com/udhos/boilerplate/envconfig"
"github.com/udhos/boilerplate/secret"
)
type config struct {
roleArnSqs string
queueURL string
roleArnSns string
topicArn string
readers int
writers int
buffer int
errorCooldownRead time.Duration
errorCooldownWrite time.Duration
copyAttributes bool
debug bool
}
func newConfig(me string) config {
env := getEnv(me)
return config{
roleArnSqs: env.String("ROLE_ARN_SQS", ""),
queueURL: env.String("QUEUE_URL", ""),
roleArnSns: env.String("ROLE_ARN_SNS", ""),
topicArn: env.String("TOPIC_ARN", ""),
readers: env.Int("READERS", 1),
writers: env.Int("WRITERS", 1),
buffer: env.Int("BUFFER", 10),
errorCooldownRead: env.Duration("READ_ERROR_COOLDOWN", 10*time.Second),
errorCooldownWrite: env.Duration("WRITE_ERROR_COOLDOWN", 10*time.Second),
copyAttributes: env.Bool("COPY_ATTRIBUTES", true),
debug: env.Bool("DEBUG", true),
}
}
func getEnv(me string) *envconfig.Env {
roleArn := os.Getenv("SECRET_ROLE_ARN")
log.Printf("SECRET_ROLE_ARN='%s'", roleArn)
secretOptions := secret.Options{
RoleSessionName: me,
RoleArn: roleArn,
}
secret := secret.New(secretOptions)
envOptions := envconfig.Options{
Secret: secret,
}
env := envconfig.New(envOptions)
return env
}