Added a config parser

Add a config.yml/config.toml file to $HOME/.config/goMP/ so that user
configurations are read.
This commit is contained in:
aditya-K2
2021-11-05 12:40:46 +05:30
parent 8e05e1a865
commit 5ad7b90844
6 changed files with 46 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/fhs/gompd/mpd"
"github.com/gdamore/tcell/v2"
"github.com/spf13/viper"
)
var Volume int64
@@ -16,9 +17,9 @@ var Repeat bool
var InsidePlaylist bool = true
func main() {
readConfig()
// Connect to MPD server
conn, err := mpd.Dial("tcp", "localhost:6600")
conn, err := mpd.Dial("tcp", "localhost:"+viper.GetString("MPD_PORT"))
if err != nil {
log.Fatalln(err)
}
@@ -27,7 +28,7 @@ func main() {
r := newRenderer()
c, _ := conn.CurrentSong()
if len(c) != 0 {
r.Start(DBDIR + c["file"])
r.Start(viper.GetString("MUSIC_DIRECTORY") + c["file"])
} else {
r.Start("stop")
}