This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
/
config.go
77 lines (68 loc) · 2.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright © 2017 MeteoGroup Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"flag"
"os"
)
var (
awsProfile = ""
awsAccessKey = ""
awsSecretKey = ""
awsRegion = ""
sqsUrl = ""
awsEndpoint = ""
kafkaBrokers = ""
kafkaTopic = ""
metricsAddress = ""
awsReadConfig = false
)
func loadConfig() {
flag.StringVar(&awsAccessKey, "aws-access-key", "", "AWS access key")
flag.StringVar(&awsSecretKey, "aws-secret-key", "", "AWS secret key")
flag.StringVar(&awsRegion, "aws-region", os.Getenv("AWS_REGION"), "AWS region")
flag.StringVar(&awsProfile, "aws-profile", os.Getenv("AWS_PROFILE"), "AWS profile")
flag.BoolVar(&awsReadConfig, "aws-read-config", false, "read AWS configuration from `~/.aws/config`")
flag.StringVar(&awsEndpoint, "aws-endpoint", os.Getenv("AWS_ENDPOINT"), "URL of the AWS endpoint")
flag.StringVar(&sqsUrl, "sqs-url", os.Getenv("SQS_URL"), "URL of the SQS queue for incomming messages")
flag.StringVar(&kafkaBrokers, "kafka-brokers", os.Getenv("KAFKA_BROKERS"), "list of Kafka brokers used for bootstrapping")
flag.StringVar(&kafkaTopic, "kafka-topic", os.Getenv("KAFKA_TOPIC"), "Kafka topic for outgoing messages")
flag.StringVar(&metricsAddress, "metrics-address", os.Getenv("METRICS_ADDRESS"), "Listening address to serve metrics")
flag.Parse()
if sqsUrl == "" {
panic("Required parameter `sqs-url` is missing.")
}
if kafkaBrokers == "" {
panic("Required parameter `kafka-brokers` is missing.")
}
if kafkaTopic == "" {
panic("Required parameter `kafka-topic` is missing.")
}
logConfig()
}
func logConfig() {
parameters := []interface{}{}
appendIfDefined := func(name string, value string) {
if (value != "") {
parameters = append(parameters, name, value)
}
}
appendIfDefined("awsProfile", awsProfile)
appendIfDefined("awsRegion", awsRegion)
appendIfDefined("awsEndpoint", awsEndpoint)
appendIfDefined("metricsAddress", metricsAddress)
appendIfDefined("sqsUrl", sqsUrl)
appendIfDefined("kafkaBrokers", kafkaBrokers)
appendIfDefined("kafkaTopic", kafkaTopic)
logInfo("starting with configuration", parameters...)
}