Defer server Stop and writing of MLS instead of call after doneSignal fired.
This commit is contained in:
parent
e53fb45bd9
commit
007691c534
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user