logmania/lib/config.go

53 lines
1.2 KiB
Go
Raw Normal View History

2017-06-11 03:34:11 +02:00
package lib
import (
"io/ioutil"
"github.com/BurntSushi/toml"
2017-08-09 08:45:45 +02:00
2017-06-11 03:34:11 +02:00
"github.com/genofire/logmania/log"
)
2017-06-13 00:21:19 +02:00
// Struct of the configuration
// e.g. under github.com/genofire/logmania/logmania_example.conf
2017-06-11 03:34:11 +02:00
type Config struct {
2017-08-09 08:45:45 +02:00
Notify NotifyConfig `toml:"notify"`
Receive ReceiveConfig `toml:"receive"`
2017-06-11 03:34:11 +02:00
}
2017-06-16 10:33:35 +02:00
type NotifyConfig struct {
StateFile string `toml:"state_file"`
XMPP struct {
2017-06-16 10:33:35 +02:00
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"`
2017-08-09 08:45:45 +02:00
IRC struct {
} `toml:"irc"`
}
type ReceiveConfig struct {
Syslog struct {
Type string `toml:"type"`
Address string `toml:"address"`
2017-08-09 08:45:45 +02:00
} `toml:"syslog"`
2017-06-16 10:33:35 +02:00
}
2017-06-13 00:21:19 +02:00
// read configuration from a file (use toml as file-format)
2017-06-11 03:34:11 +02:00
func ReadConfig(path string) (*Config, error) {
2017-08-09 08:45:45 +02:00
log.Infof("load of configfile: %s", path)
2017-06-11 03:34:11 +02:00
var config Config
file, _ := ioutil.ReadFile(path)
err := toml.Unmarshal(file, &config)
if err != nil {
return nil, err
}
return &config, nil
}