From e7afe60331940716df5ea63e59b4cd5da08b0b50 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Mon, 15 Dec 2014 16:41:15 -0800 Subject: [PATCH] Fixed config loading, some formatting --- parseconfig.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/parseconfig.go b/parseconfig.go index b9c6ee2..4ac2e90 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -9,39 +9,47 @@ package main import ( "code.google.com/p/gcfg" + "errors" + "fmt" + "os/user" ) type DjConfig struct { General struct { CommandPrefix string - SkipRatio float32 + SkipRatio float32 } Volume struct { DefaultVolume float32 - LowestVolume float32 + LowestVolume float32 HighestVolume float32 } Aliases struct { - AddAlias string - SkipAlias string + AddAlias string + SkipAlias string AdminSkipAlias string - VolumeAlias string - MoveAlias string - ReloadAlias string - KillAlias string + VolumeAlias string + MoveAlias string + ReloadAlias string + KillAlias string } Permissions struct { AdminsEnabled bool - Admins []string - AdminAdd bool - AdminSkip bool - AdminVolume bool - AdminMove bool - AdminReload bool - AdminKill bool + Admins []string + AdminAdd bool + AdminSkip bool + AdminVolume bool + AdminMove bool + AdminReload bool + AdminKill bool } } -func loadConfiguration() (error) { - return gcfg.ReadFileInto(&dj.conf, "mumbledj.gcfg") +func loadConfiguration() error { + usr, err := user.Current() + if err == nil { + return gcfg.ReadFileInto(&dj.conf, fmt.Sprintf("%s/.mumbledj/config/mumbledj.gcfg", usr.HomeDir)) + } else { + return errors.New("Configuration load failed.") + } }