Files
mam-contract/internal/ginserver/start.go
Jeffrey Duroyon 33db360b03 init
2023-10-18 19:52:34 +02:00

39 lines
869 B
Go

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