forked from traetox/gobwmon
/
config.go
46 lines (40 loc) · 1.04 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
package main
import (
"errors"
cfg "gopkg.in/gcfg.v1"
)
var (
ErrInvalidConfig = errors.New("Invalid Configuration")
defaultUpdateInterval uint = 1
defaultStorageLocation string = `/opt/gobwmon/`
defaultWebRoot string = `/opt/gobwmon/www/`
defaultLiveSize int = 120
defaultBindAddress string = `0.0.0.0:80`
)
type Config struct {
Interface []string
Update_Interval_Seconds uint
Storage_Location string
Live_Size int
Web_Server_Bind_Address string
Web_Root string
}
type fconfig struct {
Interface_Config Config
}
func NewConfig(p string) (*Config, error) {
c := Config{
Update_Interval_Seconds: defaultUpdateInterval,
Storage_Location: defaultStorageLocation,
Live_Size: defaultLiveSize,
Web_Server_Bind_Address: defaultBindAddress,
Web_Root: defaultWebRoot,
}
fc := fconfig{
Interface_Config: c,
}
if err := cfg.ReadFileInto(&fc, p); err != nil {
return nil, err
}
return &fc.Interface_Config, nil
}