logmania/lib/config.go

48 lines
1.1 KiB
Go
Raw Normal View History

2017-06-11 03:34:11 +02:00
package lib
import (
"io/ioutil"
"github.com/BurntSushi/toml"
"github.com/genofire/logmania/log"
)
type Config struct {
API struct {
Bind string `toml:"bind"`
Interactive bool `toml:"interactive"`
} `toml:"api"`
2017-06-12 23:02:03 +02:00
Notify struct {
XMPP struct {
Host string `toml:"host"`
Username string `toml:"username"`
Password string `toml:"password"`
Debug bool `toml:"debug"`
NoTLS bool `toml:"no_tls"`
Session bool `toml:"session"`
Status string `toml:"status"`
StatusMessage string `toml:"status_message"`
StartupNotify string `toml:"startup_notify"`
} `toml:"xmpp"`
} `toml:"notify"`
2017-06-11 03:34:11 +02:00
Database struct {
Type string `toml:"type"`
Connect string `toml:"connect"`
} `toml:"database"`
Webserver struct {
Enable bool `toml:"enable"`
Bind string `toml:"bind"`
} `toml:"webserver"`
}
func ReadConfig(path string) (*Config, error) {
log.Debugf("load of configfile: %s", path)
var config Config
file, _ := ioutil.ReadFile(path)
err := toml.Unmarshal(file, &config)
if err != nil {
return nil, err
}
return &config, nil
}