package ginserver import ( "github.com/gin-gonic/gin" "github.com/kratisto/mam-contract/internal/utils" "log" "net/http" "os" "os/signal" "syscall" ) func Start(injector *utils.Injector) { router := utils.Get[*gin.Engine](injector, routerInjectorKey) srv := &http.Server{ Addr: ":8080", Handler: router, } go func() { // service connections if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { log.Fatalf("listen: %s\n", err) } }() // Wait for interrupt signal to gracefully shutdown the server with // a timeout of 5 seconds. quit := make(chan os.Signal) // kill (no param) default send syscanll.SIGTERM // kill -2 is syscall.SIGINT // kill -9 is syscall. SIGKILL but can"t be catch, so don't need add it signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) <-quit log.Println("Shutdown Server ...") }