2015-04-30 00:18:08 -04:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
2015-05-07 21:28:41 -04:00
|
|
|
// Config represents the configuration for a
|
|
|
|
// specific domain. Each domain can have multiple
|
|
|
|
// hostnames, including the root domain, where
|
|
|
|
// hostname is an empty string.
|
2015-05-04 20:20:11 -04:00
|
|
|
//
|
|
|
|
// The interval is the polling time (in seconds) for
|
|
|
|
// daemon mode.
|
2015-04-30 00:18:08 -04:00
|
|
|
type Config struct {
|
2015-05-04 03:07:14 -04:00
|
|
|
Dev bool `json:"dev"`
|
|
|
|
Domain string `json:"domain"`
|
|
|
|
Hostnames []string `json:"hostnames"`
|
|
|
|
Interval int `json:"interval"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
Username string `json:"username"`
|
2015-04-30 00:18:08 -04:00
|
|
|
}
|
|
|
|
|
2015-05-07 21:28:41 -04:00
|
|
|
// LoadConfigs loads configurations from a file. The configuration
|
2015-05-04 20:20:11 -04:00
|
|
|
// is stored as an array of JSON serialized Config structs.
|
2015-04-30 00:18:08 -04:00
|
|
|
func LoadConfigs(path string) ([]Config, error) {
|
|
|
|
var configs struct {
|
|
|
|
Configs []Config
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(file, &configs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return configs.Configs, nil
|
|
|
|
}
|