-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
85 lines (73 loc) · 1.97 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
78
79
80
81
82
83
84
85
package mgostatsd
import (
"flag"
"fmt"
"time"
"github.com/vharitonsky/iniflags"
)
type strings []string
/* Mongo portion of configuration */
type Mongo struct {
Addresses []string
User string
Pass string
AuthDb string
}
/* Statsd portion of configuration */
type Statsd struct {
Host string
Port int
Env string
Cluster string
}
/* Config contains full configuration for utility */
type Config struct {
Verbose bool
Interval time.Duration
Mongo Mongo
Statsd Statsd
}
func (s *strings) String() string {
return fmt.Sprintf("%s", *s)
}
func (s *strings) Set(value string) error {
*s = append(*s, value)
return nil
}
var mongoAddresses strings
/* LoadConfig loads the configuration from command-line options */
func LoadConfig() Config {
var (
verbose = flag.Bool("verbose", false, "Verbose logging")
mongoUser = flag.String("mongo_user", "", "MongoDB User")
mongoPass = flag.String("mongo_pass", "", "MongoDB Password")
mongoAuthDb = flag.String("mongo_auth_db", "admin", "MongoDB Authentication DB")
statsdHost = flag.String("statsd_host", "localhost", "StatsD Host")
statsdPort = flag.Int("statsd_port", 8125, "StatsD Port")
statsdEnv = flag.String("statsd_env", "dev", "StatsD metric environment prefix")
statsdCluster = flag.String("statsd_cluster", "unknown", "StatsD metric cluster prefix")
interval = flag.Duration("interval", 5*time.Second, "Polling interval")
)
flag.Var(&mongoAddresses, "mongo_address", "List of mongo addresses in host:port format")
iniflags.Parse()
if len(mongoAddresses) == 0 {
mongoAddresses = append(mongoAddresses, "localhost:27017")
}
cfg := Config{
Verbose: *verbose,
Interval: *interval,
Mongo: Mongo{
Addresses: mongoAddresses,
User: *mongoUser,
Pass: *mongoPass,
AuthDb: *mongoAuthDb,
},
Statsd: Statsd{
Host: *statsdHost,
Port: *statsdPort,
Env: *statsdEnv,
Cluster: *statsdCluster,
},
}
return cfg
}