forked from stripe/veneur
/
config_parse.go
52 lines (43 loc) · 1017 Bytes
/
config_parse.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
package veneur
import (
"io"
"io/ioutil"
"os"
"time"
"gopkg.in/yaml.v2"
)
const defaultBufferSizeBytes = 1048576 * 2 // 2 MB
// ReadConfig unmarshals the config file and slurps in it's data.
func ReadConfig(path string) (c Config, err error) {
f, err := os.Open(path)
if err != nil {
return c, err
}
defer f.Close()
return readConfig(f)
}
func readConfig(r io.Reader) (c Config, err error) {
// Unfortunately the YAML package does not
// support reader inputs
// TODO(aditya) convert this when the
// upstream PR lands
bts, err := ioutil.ReadAll(r)
if err != nil {
return
}
err = yaml.Unmarshal(bts, &c)
if err != nil {
return
}
if c.Hostname == "" && !c.OmitEmptyHostname {
c.Hostname, _ = os.Hostname()
}
if c.ReadBufferSizeBytes == 0 {
c.ReadBufferSizeBytes = defaultBufferSizeBytes
}
return c, nil
}
// ParseInterval handles parsing the flush interval as a time.Duration
func (c Config) ParseInterval() (time.Duration, error) {
return time.ParseDuration(c.Interval)
}