Skip to content

Commit

Permalink
update: gracefully shutdown server
Browse files Browse the repository at this point in the history
  • Loading branch information
aschenmaker committed May 28, 2021
1 parent 20fc98e commit bec2253
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ func main() {
}
defer bdb.Close()

// Close the database on interruptor
interruptor := make(chan os.Signal, 1)
signal.Notify(interruptor, os.Interrupt)
go func() {
for range interruptor {
db.Close()
bdb.Close()
os.Exit(1)
}
}()

var n int = 1

// Start the Gofiber APP
Expand All @@ -75,6 +64,18 @@ func main() {
File: "./favicon.ico",
}))

// Close the server and database on interruptor
interruptor := make(chan os.Signal, 1)
signal.Notify(interruptor, os.Interrupt)
go func() {
for range interruptor {
app.Shutdown()
db.Close()
bdb.Close()
os.Exit(1)
}
}()

/**
* fetch a short ID and redirect
* @param `shortURL` from URL
Expand Down

0 comments on commit bec2253

Please sign in to comment.