gin-gonic / website

Official website and document for Gin
https://gin-gonic.com/
MIT License
121 stars 204 forks source link

Graceful restart or stop #283

Open mattmurphy-github opened 2 months ago

mattmurphy-github commented 2 months ago

I would recommend checking for context.DeadlineExceeded instead of "catching" <-ctx.Done() in a select.

For example;

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() err := srv.Shutdown(ctx) if errors.Is(err, context.DeadlineExceeded) { log.Println("Timeout of 5 seconds.") }