Files
noscomptes-back/internal/ginserver/start.go
2023-10-03 00:40:01 +02:00

39 lines
848 B
Go

package ginserver
import (
"github.com/gin-gonic/gin"
"log"
"net/http"
"nos-comptes/internal/utils"
"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 ...")
}