Gin wrapper to enable graceful termination when shutting down a process
package main
import (
"context"
"net/http"
"os/signal"
"syscall"
"github.com/gin-contrib/graceful"
"github.com/gin-gonic/gin"
)
func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
router, err := graceful.Default()
if err != nil {
panic(err)
}
defer router.Close()
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Welcome Gin Server")
})
if err := router.RunWithContext(ctx); err != nil && err != context.Canceled {
panic(err)
}
}