gostations/filer.go

47 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"log"
"os"
"path/filepath"
)
2021-03-17 13:45:54 +00:00
func createIniFile(fpath string) []error {
log.Printf("Creating config file: %s\n", fpath)
2021-03-17 13:45:54 +00:00
var errorlist []error
if err := os.MkdirAll(filepath.Dir(fpath), 0770); err != nil {
2021-03-17 13:45:54 +00:00
errorlist = append(errorlist, err)
}
file, err := os.Create(fpath)
if err != nil {
2021-03-17 13:45:54 +00:00
errorlist = append(errorlist, err)
}
2021-03-17 13:45:54 +00:00
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)
}
2021-03-17 13:45:54 +00:00
defer func() {
err := file.Close()
if err != nil {
errorlist = append(errorlist, err)
}
}()
2021-03-17 13:45:54 +00:00
return errorlist
}