From 3ef213ab0d825fed53cf2cc29b2cc3e073974257 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 27 May 2023 00:36:23 +0400 Subject: [PATCH] Changed main a little. --- cmd/dwelling-radio/main.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index a3bcd41..a2ef641 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -18,31 +18,29 @@ import ( "git.arav.su/Arav/httpr" ) -var version string +var ( + configPath *string = flag.String("conf", "config.yaml", "path to configuration file") + noLiquidsoap *bool = flag.Bool("no-liquidsoap", false, "don't run liquidsoap") -var configPath *string = flag.String("conf", "config.yaml", "path to configuration file") -var noLiquidsoap *bool = flag.Bool("no-liquidsoap", false, "don't run liquidsoap") -var showVersion *bool = flag.Bool("v", false, "show version") + showVersion *bool = flag.Bool("v", false, "show version") +) + +var version string func main() { flag.Parse() + log.SetFlags(log.Lshortfile) if *showVersion { fmt.Println("dwelling-radio ver.", version, "\nCopyright (c) 2022,2023 Alexander \"Arav\" Andreev ") return } - log.SetFlags(log.Lshortfile) - config, err := configuration.Load(*configPath) if err != nil { log.Fatalln(err) } - if typ, addr := config.SplitNetworkAddress(); typ == "unix" { - defer os.Remove(addr) - } - if data, err := os.ReadFile(config.MostListenedSongPath); err == nil { if err := radio.LoadMostListenedSong(data); err != nil { log.Fatalln(err) @@ -62,10 +60,8 @@ func main() { } defer func() { - if err := liquid.Stop(); err != nil { - if !errors.Is(err, radio.ErrLiquidsoapNotRunning) { - log.Println(err) - } + if err := liquid.Stop(); err != nil && !errors.Is(err, radio.ErrLiquidsoapNotRunning) { + log.Println(err) } }() } @@ -93,6 +89,10 @@ func main() { log.Fatalln(err) } + if typ, addr := config.SplitNetworkAddress(); typ == "unix" { + defer os.Remove(addr) + } + doneSignal := make(chan os.Signal, 1) signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSEGV)