fix linter issues

This commit is contained in:
Greg Gauthier 2021-03-17 13:45:54 +00:00
parent 56b1ce1c4b
commit b6e5c15d1c
4 changed files with 42 additions and 21 deletions

View File

@ -48,7 +48,7 @@ func GetStations(qstring string) ([]stationRecord, error){
urlstr := fmt.Sprintf("https://%s/json/stations/search?%s&limit=%d",GetApiHost(),qstring,maxitems())
resp, err := http.Get(urlstr)
if err != nil {
log.Printf(err.Error())
log.Print(err.Error())
}
defer resp.Body.Close()

View File

@ -28,10 +28,12 @@ func configStat(configFile string) string{
if _, err := os.Stat(configFile); errors.Is(err, os.ErrNotExist) {
log.Printf("Your stations config file seems to be missing. A default will be generated.")
err = createIniFile(configFile)
errs := createIniFile(configFile)
for _, err := range errs {
if err != nil {
log.Printf("Erorr creating ini file...")
log.Fatal(err.Error())
log.Printf("Erorr: %s", err.Error())
log.Fatal("Cannot continue.")
}
}
}
return configFile

View File

@ -6,32 +6,47 @@ import (
"path/filepath"
)
func createDir(fpath string) error {
if err := os.Mkdir(filepath.Dir(fpath + string(filepath.Separator)), 0770); err != nil {
return err
func closeFile(file *os.File, errorlist []error) {
err := file.Close()
if err != nil {
errorlist = append(errorlist, err)
}
return nil
}
func createIniFile(fpath string) error {
func createIniFile(fpath string) []error {
log.Printf("Creating config file: %s\n", fpath)
var errorlist []error
if err := os.MkdirAll(filepath.Dir(fpath), 0770); err != nil {
return err
errorlist = append(errorlist, err)
}
file, err := os.Create(fpath)
if err != nil {
log.Fatal(err.Error())
return err
errorlist = append(errorlist, err)
}
_, err = file.Write([]byte("[DEFAULT]\n"))
_, err = file.Write([]byte("radio_browser.api=all.api.radio-browser.info\n"))
_, err = file.Write([]byte("player.command=mpv\n"))
_, err = file.Write([]byte("player.options=--no-video\n"))
_, err = file.Write([]byte("menu_items.max=9999\n"))
defer file.Close()
return err
if _, err := file.Write([]byte("[DEFAULT]\n")); err != nil {
errorlist = append(errorlist, err)
}
if _, err := file.Write([]byte("radio_browser.api=all.api.radio-browser.info\n")); err != nil {
errorlist = append(errorlist, err)
}
if _, err := file.Write([]byte("player.command=mpv\n")); err != nil {
errorlist = append(errorlist, err)
}
if _, err := file.Write([]byte("player.options=--no-video\n")); err != nil {
errorlist = append(errorlist, err)
}
if _, err := file.Write([]byte("menu_items.max=9999\n")); err != nil {
errorlist = append(errorlist, err)
}
defer func() {
err := file.Close()
if err != nil {
errorlist = append(errorlist, err)
}
}()
return errorlist
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"log"
"os"
"github.com/dixonwille/wmenu/v5"
@ -30,7 +31,10 @@ func RadioMenu(stations []stationRecord) *wmenu.Menu {
fmt.Printf("Streaming: " + opts[0].Text + "\n")
stdout, _ := subExecute(player(), options(), val)
fmt.Println(stdout)
menu.Run()
err := menu.Run()
if err != nil {
log.Fatal("Oops! " + err.Error())
}
return nil
})
for _, station := range stations {