/
config.go
39 lines (32 loc) · 1.01 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
package config
import (
"io/ioutil"
"log"
"os"
"time"
yaml "gopkg.in/yaml.v2"
)
// Config for the app
type Config struct {
ElasticsearchURL string `yaml:"elasticsearch.url"`
ElasticsearchMaxRetries int `yaml:"elasticsearch.max.retries"`
ElasticIndexPerfix string `yaml:"elasticsearch.index.perfix"`
ElasticType string `yaml:"elasticsearch.type"`
RemoteTimeout time.Duration `yaml:"web.timeout"`
ListenAddr string `yaml:"web.listen.addr"`
TelemetryPath string `yaml:"web.telemetry.path"`
AwsElasticSearchService bool `yaml:"elasticsearch.aws.service"`
}
// GetConfig returns the app's configuration described on config.yaml on root
func GetConfig() *Config {
cfg := &Config{}
yamlFile, err := ioutil.ReadFile(os.Getenv("CONFIG_PATH"))
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, cfg)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return cfg
}