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()) urlstr := fmt.Sprintf("https://%s/json/stations/search?%s&limit=%d",GetApiHost(),qstring,maxitems())
resp, err := http.Get(urlstr) resp, err := http.Get(urlstr)
if err != nil { if err != nil {
log.Printf(err.Error()) log.Print(err.Error())
} }
defer resp.Body.Close() 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) { 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.") 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 { if err != nil {
log.Printf("Erorr creating ini file...") log.Printf("Erorr: %s", err.Error())
log.Fatal(err.Error()) log.Fatal("Cannot continue.")
}
} }
} }
return configFile return configFile

View File

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

View File

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