2020-04-09 15:32:16 +00:00
|
|
|
package main
|
|
|
|
|
2020-04-10 06:46:34 +00:00
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config stores application configuration
|
|
|
|
type Config struct {
|
|
|
|
Secure bool
|
|
|
|
Hostname string
|
|
|
|
Port int
|
|
|
|
Path string
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the configuration
|
|
|
|
func loadConfig(path string) Config {
|
|
|
|
|
|
|
|
// Load data
|
|
|
|
dat, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Could not read configuration: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode data
|
|
|
|
conf := Config{}
|
|
|
|
err = yaml.UnmarshalStrict(dat, &conf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Could not decode configuration: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf
|
2020-04-09 15:32:16 +00:00
|
|
|
}
|