Fixed configuration load

This commit is contained in:
Matthieu Grieger 2014-12-13 09:22:30 -08:00
parent 1c768c9cb2
commit 0629776b81
2 changed files with 15 additions and 4 deletions

View file

@ -31,6 +31,8 @@ func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
dj.conf, err = loadConfiguration()
if err == nil {
fmt.Println("Configuration successfully loaded!")
} else {
panic(err)
}
}

View file

@ -9,6 +9,8 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"github.com/BurntSushi/toml"
)
@ -54,9 +56,16 @@ type permissionsConfig struct {
}
func loadConfiguration() (config, error) {
var conf config
if _, err := toml.Decode("config.toml", &conf); err != nil {
return conf, errors.New("Configuration load failed.")
file, err := ioutil.ReadFile("config.toml")
if err != nil {
panic(err)
} else {
fileString := string(file)
var conf config
if _, err := toml.Decode(fileString, &conf); err != nil {
return conf, errors.New("Configuration load failed.")
}
return conf, nil
}
return conf, nil
}