Fixed configuration load
This commit is contained in:
parent
1c768c9cb2
commit
0629776b81
2
main.go
2
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue