feat: add crono to rest
This commit is contained in:
parent
ae76938f48
commit
da303b27e0
|
@ -42,19 +42,17 @@ func main() {
|
||||||
professionalRepo := employee_wi.NewRepo(employeeWICollection)
|
professionalRepo := employee_wi.NewRepo(employeeWICollection)
|
||||||
|
|
||||||
restServer := http.
|
restServer := http.
|
||||||
NewRestServer(cfg).
|
NewRestServer(cfg, cr).
|
||||||
WithProfessionalHandler(services.NewEmployeeWIService(ctx, professionalRepo))
|
WithProfessionalHandler(services.NewEmployeeWIService(ctx, professionalRepo))
|
||||||
|
|
||||||
cr.MarkAndRestart("dependencies loaded")
|
cr.MarkAndRestart("dependencies loaded")
|
||||||
|
log.Println(cfg)
|
||||||
go func() {
|
go func() {
|
||||||
cr.Restart()
|
|
||||||
if err = restServer.Start(cfg.ApiPort, ""); err != nil {
|
if err = restServer.Start(cfg.ApiPort, ""); err != nil {
|
||||||
log.Fatalln("restServer.Start", err)
|
log.Fatalln("restServer.Start", err)
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
cr.MarkAndRestart("server up")
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
restServer.Shutdown()
|
restServer.Shutdown()
|
||||||
log.Println("gracefully shutdown")
|
log.Println("gracefully shutdown")
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"gitea.urkob.com/urko/ess-etl-go/config"
|
"gitea.urkob.com/urko/ess-etl-go/config"
|
||||||
"gitea.urkob.com/urko/ess-etl-go/internal/api/http/handler"
|
"gitea.urkob.com/urko/ess-etl-go/internal/api/http/handler"
|
||||||
"gitea.urkob.com/urko/ess-etl-go/internal/services"
|
"gitea.urkob.com/urko/ess-etl-go/internal/services"
|
||||||
|
"gitea.urkob.com/urko/ess-etl-go/pkg/crono"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
|
@ -15,12 +16,14 @@ import (
|
||||||
type restServer struct {
|
type restServer struct {
|
||||||
app *fiber.App
|
app *fiber.App
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
|
cr *crono.Crono
|
||||||
employeeWIHdl *handler.EmployeeWorkInformationHandler
|
employeeWIHdl *handler.EmployeeWorkInformationHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRestServer(cfg *config.Config) *restServer {
|
func NewRestServer(cfg *config.Config, cr *crono.Crono) *restServer {
|
||||||
return &restServer{
|
return &restServer{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
cr: cr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +45,7 @@ func (s *restServer) Start(apiPort, bearerToken string) error {
|
||||||
return s.employeeWIHdl.Get(c)
|
return s.employeeWIHdl.Get(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
s.app.Get("/employee_wi/:id", func(c *fiber.Ctx) error {
|
s.cr.MarkAndRestart("server up")
|
||||||
return s.employeeWIHdl.Get(c)
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := s.app.Listen(":" + apiPort); err != nil {
|
if err := s.app.Listen(":" + apiPort); err != nil {
|
||||||
return fmt.Errorf("app.Listen: %s", err)
|
return fmt.Errorf("app.Listen: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue