1
0

Defer server Stop and writing of MLS instead of call after doneSignal fired.

This commit is contained in:
Alexander Andreev 2023-08-21 04:39:38 +04:00
parent e53fb45bd9
commit 007691c534
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -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)
}
}