Move controller to the template renderer (#68)
This commit is contained in:
parent
6a7070a729
commit
5531e0bec2
26 changed files with 654 additions and 679 deletions
|
|
@ -1,7 +1,11 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/mikestefanello/pagoda/pkg/htmx"
|
||||
"github.com/mikestefanello/pagoda/pkg/services"
|
||||
)
|
||||
|
||||
|
|
@ -25,3 +29,24 @@ func Register(h Handler) {
|
|||
func GetHandlers() []Handler {
|
||||
return handlers
|
||||
}
|
||||
|
||||
// redirect redirects to a given route name with optional route parameters
|
||||
func redirect(ctx echo.Context, route string, routeParams ...any) error {
|
||||
url := ctx.Echo().Reverse(route, routeParams...)
|
||||
|
||||
if htmx.GetRequest(ctx).Boosted {
|
||||
htmx.Response{
|
||||
Redirect: url,
|
||||
}.Apply(ctx)
|
||||
|
||||
return nil
|
||||
} else {
|
||||
return ctx.Redirect(http.StatusFound, url)
|
||||
}
|
||||
}
|
||||
|
||||
// fail is a helper to fail a request by returning a 500 error and logging the error
|
||||
func fail(err error, log string) error {
|
||||
// The error handler will handle logging
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("%s: %v", log, err))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue