feat: add crono to rest

This commit is contained in:
Urko 2023-04-03 19:01:32 +02:00
parent ae76938f48
commit da303b27e0
2 changed files with 7 additions and 9 deletions

View File

@ -42,19 +42,17 @@ func main() {
professionalRepo := employee_wi.NewRepo(employeeWICollection)
restServer := http.
NewRestServer(cfg).
NewRestServer(cfg, cr).
WithProfessionalHandler(services.NewEmployeeWIService(ctx, professionalRepo))
cr.MarkAndRestart("dependencies loaded")
log.Println(cfg)
go func() {
cr.Restart()
if err = restServer.Start(cfg.ApiPort, ""); err != nil {
log.Fatalln("restServer.Start", err)
cancel()
}
cr.MarkAndRestart("server up")
}()
<-ctx.Done()
restServer.Shutdown()
log.Println("gracefully shutdown")

View File

@ -7,6 +7,7 @@ import (
"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/services"
"gitea.urkob.com/urko/ess-etl-go/pkg/crono"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
@ -15,12 +16,14 @@ import (
type restServer struct {
app *fiber.App
cfg *config.Config
cr *crono.Crono
employeeWIHdl *handler.EmployeeWorkInformationHandler
}
func NewRestServer(cfg *config.Config) *restServer {
func NewRestServer(cfg *config.Config, cr *crono.Crono) *restServer {
return &restServer{
cfg: cfg,
cr: cr,
}
}
@ -42,10 +45,7 @@ func (s *restServer) Start(apiPort, bearerToken string) error {
return s.employeeWIHdl.Get(c)
})
s.app.Get("/employee_wi/:id", func(c *fiber.Ctx) error {
return s.employeeWIHdl.Get(c)
})
s.cr.MarkAndRestart("server up")
if err := s.app.Listen(":" + apiPort); err != nil {
return fmt.Errorf("app.Listen: %s", err)
}