yanic/models/config.go

56 lines
1.4 KiB
Go
Raw Normal View History

2016-03-07 08:52:52 +00:00
package models
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
//Config the config File of this daemon
type Config struct {
2016-03-09 02:26:08 +00:00
Respondd struct {
2016-03-07 08:52:52 +00:00
Enable bool `yaml:"enable"`
Port string `yaml:"port"`
Address string `yaml:"address"`
CollectInterval int `yaml:"collectinterval"`
2016-03-09 02:26:08 +00:00
} `yaml:"respondd"`
2016-03-07 08:52:52 +00:00
Webserver struct {
Enable bool `yaml:"enable"`
Port string `yaml:"port"`
Address string `yaml:"address"`
Webroot string `yaml:"webroot"`
2016-05-14 10:31:43 +00:00
Api struct {
2016-05-16 10:24:50 +00:00
Passphrase string `yaml:"passphrase"`
2016-05-17 09:07:14 +00:00
NewNodes bool `yaml:"newnodes"`
2016-05-14 10:31:43 +00:00
Aliases bool `yaml:"aliases"`
} `yaml:"api"`
2016-03-07 08:52:52 +00:00
} `yaml:"webserver"`
Nodes struct {
2016-03-07 11:05:53 +00:00
Enable bool `yaml:"enable"`
NodesPath string `yaml:"nodes_path"`
GraphsPath string `yaml:"graphs_path"`
AliasesPath string `yaml:"aliases_path"`
SaveInterval int `yaml:"saveinterval"`
VpnAddresses []string `yaml:"vpn_addresses"`
2016-03-07 08:52:52 +00:00
} `yaml:"nodes"`
2016-03-12 02:36:02 +00:00
Influxdb struct {
Enable bool `yaml:"enable"`
2016-04-29 10:39:53 +00:00
Addr string `yaml:"host"`
2016-03-12 02:36:02 +00:00
Database string `yaml:"database"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
2016-03-07 08:52:52 +00:00
}
2016-03-20 18:54:43 +00:00
// reads a config models by path to a yml file
func ReadConfigFile(path string) *Config {
2016-03-07 08:52:52 +00:00
config := &Config{}
file, _ := ioutil.ReadFile(path)
err := yaml.Unmarshal(file, &config)
if err != nil {
log.Fatal(err)
}
return config
}