Skip to content

Graceful allows to restart and/or switch gin.Engine without dropping existing conns

License

Notifications You must be signed in to change notification settings

gin-contrib/graceful

Repository files navigation

graceful

Run Tests codecov Go Report Card GoDoc

Gin wrapper to enable graceful termination when shutting down a process

Example

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)
  }
}

About

Graceful allows to restart and/or switch gin.Engine without dropping existing conns

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages