All checks were successful
continuous-integration/drone/push Build is passing
40 lines
849 B
Go
40 lines
849 B
Go
package server
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.pbiernat.dev/egommerce/go-api-pkg/fluentd"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func SetupRoutes(s *Server) {
|
|
s.App.Get("/health", s.HealthHandler)
|
|
s.App.Get("/config", s.ConfigHandler)
|
|
|
|
api := s.App.Group("/api")
|
|
v1 := api.Group("/v1")
|
|
order := v1.Group("/order")
|
|
order.Put("/:orderId/status", s.UpdateOrderStatusHandler)
|
|
}
|
|
|
|
func SetupMiddlewares(s *Server) {
|
|
s.App.Use(LoggingMiddleware(s.log))
|
|
}
|
|
|
|
// Middlewares
|
|
func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error {
|
|
return func(c *fiber.Ctx) error {
|
|
path := string(c.Request().URI().Path())
|
|
if strings.Contains(path, "/health") {
|
|
return c.Next()
|
|
}
|
|
|
|
log.Log("Request: %s, remote: %s, via: %s",
|
|
c.Request().URI().String(),
|
|
c.Context().RemoteIP().String(),
|
|
string(c.Context().UserAgent()))
|
|
|
|
return c.Next()
|
|
}
|
|
}
|