-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
47 lines (39 loc) · 1.62 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
package main
import (
"flag"
"io/ioutil"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
)
// Configuration file
var configLocation = flag.String("config", "./config.yml", "Location of yaml configuration file")
// Configuration store application configuration information
type Configuration struct {
ElasticClientBatchSize int `yaml:"elastic-client-batch-size"`
ElasticClientWorkers int `yaml:"elastic-client-workers"`
ElasticClientFlushInterval int `yaml:"elastic-client-flush-interval"`
ElasticClientStatsEnabled bool `yaml:"elastic-client-stats-enabled"`
Elastic []string `yaml:"elastic-hosts"`
ElasticUser string `yaml:"elastic-user,omitempty"`
ElasticPassword string `yaml:"elastic-password,omitempty"`
ElasticSniff bool `yaml:"elastic-sniff-discovery"`
ElasticIndexName string `yaml:"elastic-index"`
GDAXMarkets []string `yaml:"gdax-markets"`
LogLevel string `yaml:"log-level,omitempty"` // Valid values are info or debug. Defaults to info.
}
// NewConfiguration creates a new Configuration from the given file path
func NewConfiguration(configLocation string) (*Configuration, error) {
yml, err := ioutil.ReadFile(configLocation)
if err != nil {
return nil, errors.Wrapf(err, "Unable read configuration file %v", configLocation)
}
config := Configuration{}
err = yaml.Unmarshal(yml, &config)
if err != nil {
return nil, errors.Wrapf(err, "Error parsing configuration file %v", configLocation)
}
if config.LogLevel == "" {
config.LogLevel = "info"
}
return &config, nil
}