2017-04-10 16:54:12 +00:00
|
|
|
package runtime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Config the config File of this daemon
|
|
|
|
type Config struct {
|
|
|
|
Respondd struct {
|
|
|
|
Enable bool `toml:"enable"`
|
2017-06-14 07:44:15 +00:00
|
|
|
Synchronize Duration `toml:"synchronize"`
|
2017-10-18 16:22:14 +00:00
|
|
|
Interfaces []string `toml:"interfaces"`
|
2017-11-21 14:12:06 +00:00
|
|
|
Sites []string `toml:"sites"`
|
2017-04-10 16:54:12 +00:00
|
|
|
Port int `toml:"port"`
|
|
|
|
CollectInterval Duration `toml:"collect_interval"`
|
|
|
|
}
|
|
|
|
Webserver struct {
|
|
|
|
Enable bool `toml:"enable"`
|
|
|
|
Bind string `toml:"bind"`
|
|
|
|
Webroot string `toml:"webroot"`
|
|
|
|
}
|
2018-01-05 21:48:32 +00:00
|
|
|
Nodes NodesConfig
|
2018-01-03 14:41:40 +00:00
|
|
|
Database DatabaseConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodesConfig struct {
|
|
|
|
StatePath string `toml:"state_path"`
|
|
|
|
SaveInterval Duration `toml:"save_interval"` // Save nodes periodically
|
|
|
|
OfflineAfter Duration `toml:"offline_after"` // Set node to offline if not seen within this period
|
|
|
|
PruneAfter Duration `toml:"prune_after"` // Remove nodes after n days of inactivity
|
|
|
|
Output map[string]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type DatabaseConfig struct {
|
|
|
|
DeleteInterval Duration `toml:"delete_interval"` // Delete stats of nodes every n minutes
|
|
|
|
DeleteAfter Duration `toml:"delete_after"` // Delete stats of nodes till now-deletetill n minutes
|
|
|
|
Connection map[string]interface{}
|
2017-04-10 16:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadConfigFile reads a config model from path of a yml file
|
|
|
|
func ReadConfigFile(path string) (config *Config, err error) {
|
|
|
|
config = &Config{}
|
|
|
|
|
|
|
|
file, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
2017-09-17 01:26:19 +00:00
|
|
|
return nil, err
|
2017-04-10 16:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = toml.Unmarshal(file, config)
|
|
|
|
if err != nil {
|
2017-09-17 01:26:19 +00:00
|
|
|
return nil, err
|
2017-04-10 16:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|