60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
|
package http
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
|
||
|
"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"
|
||
|
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||
|
)
|
||
|
|
||
|
type restServer struct {
|
||
|
app *fiber.App
|
||
|
cfg *config.Config
|
||
|
employeeWIHdl *handler.EmployeeWorkInformationHandler
|
||
|
}
|
||
|
|
||
|
func NewRestServer(cfg *config.Config) *restServer {
|
||
|
return &restServer{
|
||
|
cfg: cfg,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *restServer) WithProfessionalHandler(employeeWISrv services.EmployeeWIService) *restServer {
|
||
|
s.employeeWIHdl = handler.NewEmployeeWorkInformation(employeeWISrv)
|
||
|
return s
|
||
|
}
|
||
|
func (s *restServer) Start(apiPort, bearerToken string) error {
|
||
|
s.app = fiber.New()
|
||
|
|
||
|
s.app.Use(cors.New(cors.Config{
|
||
|
AllowMethods: "GET,POST,OPTIONS",
|
||
|
AllowOrigins: "*",
|
||
|
AllowHeaders: "Origin, Accept, Content-Type, X-CSRF-Token, Authorization",
|
||
|
ExposeHeaders: "Origin",
|
||
|
}))
|
||
|
|
||
|
s.app.Get("/employee_wi/:id", func(c *fiber.Ctx) error {
|
||
|
return s.employeeWIHdl.Get(c)
|
||
|
})
|
||
|
|
||
|
s.app.Get("/employee_wi/:id", func(c *fiber.Ctx) error {
|
||
|
return s.employeeWIHdl.Get(c)
|
||
|
})
|
||
|
|
||
|
if err := s.app.Listen(":" + apiPort); err != nil {
|
||
|
return fmt.Errorf("app.Listen: %s", err)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (s *restServer) Shutdown() {
|
||
|
if err := s.app.Server().Shutdown(); err != nil {
|
||
|
log.Printf("app.Server().Shutdown(): %s\n", err)
|
||
|
}
|
||
|
}
|