rentease/internal/server/routes.go
2024-02-16 18:20:15 +01:00

33 lines
1.1 KiB
Go

package server
import (
"os"
"strings"
"github.com/labstack/echo/v4/middleware"
)
func (s Server) MountHandlers() {
// config
s.Router.HideBanner = true
s.Router.Debug = strings.ToLower(os.Getenv("DEBUG")) == "true"
s.Router.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_rfc3339} [${method}: ${status}] ${uri}; ip=${remote_ip}; ${latency_human}; ${user_agent}\n",
}))
s.Router.HTTPErrorHandler = s.customHTTPErrorHandler
// middlewares
s.Router.Use(middleware.Recover())
s.Router.Use(middleware.Secure())
// static assets
s.Router.Static("/static", "assets")
// landing page
s.Router.GET("/", handleHomePage())
s.Router.GET("/bookings", handleListBookingPage(s.bs))
s.Router.GET("/bookings/new", handleNewBookingPage())
s.Router.POST("/bookings/new", handleCreateBooking(s.bs))
s.Router.GET("/bookings/:id", handleBookingPage(s.bs))
s.Router.POST("bookings/:id/items", handleCreateItem(s.bs))
s.Router.GET("/reports", handleReportsPage())
s.Router.GET("/reports/do", handleComputeReport(s.bs))
s.Router.GET("/pdf", handleCreateInvoicePdf(s.ps))
}