yanic/models/config.go

57 lines
1.2 KiB
Go
Raw Normal View History

2016-03-07 08:52:52 +00:00
package models
import (
"io/ioutil"
"github.com/influxdata/toml"
2016-03-07 08:52:52 +00:00
)
//Config the config File of this daemon
type Config struct {
2016-03-09 02:26:08 +00:00
Respondd struct {
Enable bool
Interface string
Port int
CollectInterval Duration
}
2016-03-07 08:52:52 +00:00
Webserver struct {
Enable bool
2017-01-29 19:06:56 +00:00
Bind string
Webroot string
}
2016-03-07 08:52:52 +00:00
Nodes struct {
Enable bool
NodesVersion int
NodesPath string
GraphPath string
StatePath string
SaveInterval Duration // Save nodes periodically
OfflineAfter Duration // Set node to offline if not seen within this period
PruneAfter Duration // Remove nodes after n days of inactivity
}
2016-03-12 02:36:02 +00:00
Influxdb struct {
Enable bool
Address string
Database string
Username string
Password string
DeleteInterval Duration // Delete stats of nodes every n minutes
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
2016-03-12 02:36:02 +00:00
}
2016-03-07 08:52:52 +00:00
}
// ReadConfigFile reads a config model from path of a yml file
2016-03-20 18:54:43 +00:00
func ReadConfigFile(path string) *Config {
2016-03-07 08:52:52 +00:00
config := &Config{}
file, err := ioutil.ReadFile(path)
2016-03-07 08:52:52 +00:00
if err != nil {
panic(err)
2016-03-07 08:52:52 +00:00
}
if err := toml.Unmarshal(file, config); err != nil {
panic(err)
}
2016-03-07 08:52:52 +00:00
return config
}