diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index ef8fdd3..27c42d5 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -73,14 +73,19 @@ func main() { log.Fatalln(err) } + defer func() { + err := os.WriteFile(*mostListenedSongPath, radio.StoreMostListenedSong(), fs.ModePerm) + if err != nil { + log.Println("Failed to store most listened song:", err) + } + + if err := srv.Stop(); err != nil { + log.Fatalln(err) + } + }() + doneSignal := make(chan os.Signal, 1) signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSEGV) <-doneSignal - - os.WriteFile(*mostListenedSongPath, radio.StoreMostListenedSong(), fs.ModePerm) - - if err := srv.Stop(); err != nil { - log.Fatalln(err) - } }