From 0629776b81c9377e963d66192a460c944a030d52 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Sat, 13 Dec 2014 09:22:30 -0800 Subject: [PATCH] Fixed configuration load --- main.go | 2 ++ parseconfig.go | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 32d86b3..3307af0 100644 --- a/main.go +++ b/main.go @@ -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) } } diff --git a/parseconfig.go b/parseconfig.go index a6157d9..aa90032 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -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 + }