yanic/models/config.go

60 lines
1.8 KiB
Go
Raw Normal View History

2016-03-07 09:52:52 +01:00
package models
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
//Config the config File of this daemon
type Config struct {
2016-03-09 03:26:08 +01:00
Respondd struct {
2016-03-07 09:52:52 +01:00
Enable bool `yaml:"enable"`
2016-06-16 18:03:45 +02:00
Interface string `yaml:"interface"`
2016-03-07 09:52:52 +01:00
CollectInterval int `yaml:"collectinterval"`
2016-03-09 03:26:08 +01:00
} `yaml:"respondd"`
2016-03-07 09:52:52 +01:00
Webserver struct {
2016-06-16 18:03:45 +02:00
Enable bool `yaml:"enable"`
Port string `yaml:"port"`
Address string `yaml:"address"`
Webroot string `yaml:"webroot"`
API struct {
2016-05-16 12:24:50 +02:00
Passphrase string `yaml:"passphrase"`
2016-06-16 18:03:45 +02:00
NewNodes bool `yaml:"newnodes"`
Aliases bool `yaml:"aliases"`
2016-05-14 12:31:43 +02:00
} `yaml:"api"`
2016-03-07 09:52:52 +01:00
} `yaml:"webserver"`
Nodes struct {
Enable bool `yaml:"enable"`
NodesDynamicPath string `yaml:"nodes_path"`
NodesV1Path string `yaml:"nodesv1_path"`
NodesV2Path string `yaml:"nodesv2_path"`
GraphsPath string `yaml:"graphs_path"`
AliasesPath string `yaml:"aliases_path"`
SaveInterval int `yaml:"saveinterval"` // Save nodes every n seconds
MaxAge int `yaml:"max_age"` // Remove nodes after n days of inactivity
2016-03-07 09:52:52 +01:00
} `yaml:"nodes"`
2016-03-12 03:36:02 +01:00
Influxdb struct {
2016-11-26 13:11:21 +01:00
Enable bool `yaml:"enable"`
Addr string `yaml:"host"`
Database string `yaml:"database"`
Username string `yaml:"username"`
Password string `yaml:"password"`
SaveInterval int `yaml:"saveinterval"` // Save nodes every n seconds
DeleteInterval int `yaml:"deleteinterval"` // Delete stats of nodes every n minutes
DeleteTill int `yaml:"deletetill"` // Delete stats of nodes till now-deletetill n minutes
2016-03-12 03:36:02 +01:00
}
2016-03-07 09:52:52 +01:00
}
// ReadConfigFile reads a config model from path of a yml file
2016-03-20 19:54:43 +01:00
func ReadConfigFile(path string) *Config {
2016-03-07 09:52:52 +01:00
config := &Config{}
file, _ := ioutil.ReadFile(path)
err := yaml.Unmarshal(file, &config)
if err != nil {
log.Fatal(err)
}
return config
}