Enhance graceful shutdown and logging for HTTP server
- Implemented graceful shutdown for the HTTP server, allowing for a controlled shutdown process with a timeout. - Added logging for shutdown signals and server exit to improve traceability during application termination. - Introduced IP blacklist configuration to enhance security by blocking specified IP addresses. - Updated database cache configurations to allow dynamic adjustment via environment variables for better performance tuning.
This commit is contained in:
5
main.go
5
main.go
@@ -282,11 +282,14 @@ func main() {
|
||||
select {
|
||||
case <-sigs:
|
||||
fmt.Printf("\r")
|
||||
cancel()
|
||||
log.I.F("received shutdown signal, starting graceful shutdown")
|
||||
cancel() // This will trigger HTTP server shutdown
|
||||
<-quit // Wait for HTTP server to shut down
|
||||
chk.E(db.Close())
|
||||
log.I.F("exiting")
|
||||
return
|
||||
case <-quit:
|
||||
log.I.F("application quit signal received")
|
||||
cancel()
|
||||
chk.E(db.Close())
|
||||
log.I.F("exiting")
|
||||
|
||||
Reference in New Issue
Block a user