From bc4091f63963e9d6ef15b72725e2093ae9126566 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Sat, 13 Dec 2014 09:47:42 -0800 Subject: [PATCH] More changes to config, not working yet --- commands.go | 2 ++ main.go | 2 +- parseconfig.go | 21 ++++++--------------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/commands.go b/commands.go index 4975ffd..8cdd44e 100644 --- a/commands.go +++ b/commands.go @@ -59,6 +59,8 @@ func parseCommand(username, command string) { if success { fmt.Println("Kill successful!") } + case "test": + fmt.Printf("Title: %s\n", dj.conf.title) } } diff --git a/main.go b/main.go index 3307af0..002c3cf 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ type mumbledj struct { client *gumble.Client keepAlive chan bool defaultChannel string - conf config + conf djConfig } func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) { diff --git a/parseconfig.go b/parseconfig.go index aa90032..6cc0076 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -9,12 +9,10 @@ package main import ( "errors" - "fmt" - "io/ioutil" "github.com/BurntSushi/toml" ) -type config struct { +type djConfig struct { title string general generalConfig volume volumeConfig @@ -55,17 +53,10 @@ type permissionsConfig struct { adminKill bool `toml:"admin_kill"` } -func loadConfiguration() (config, error) { - 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 +func loadConfiguration() (djConfig, error) { + var conf djConfig + if _, err := toml.DecodeFile("config.toml", &conf); err != nil { + return conf, errors.New("Configuration load failed.") } - + return conf, nil }