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