order-service/src/internal/app/server/router.go
Piotr Biernat f2f8a40bd9
All checks were successful
continuous-integration/drone/push Build is passing
Added wait-for-it.sh script and fetching config from consul KV store
2022-12-07 02:51:47 +01:00

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()
}
}