handlers/index: refactor to use c.Render
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-05-11 05:01:19 +02:00
parent f80e06078a
commit 468e20da0a
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

View File

@ -3,7 +3,6 @@ package handlers
import (
"net/http"
modtmpl "git.dotya.ml/mirre-mt/pcmt/modules/template"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
)
@ -23,10 +22,11 @@ func Index() echo.HandlerFunc {
return c.Redirect(http.StatusFound, "/home")
}
tpl := modtmpl.Get("index.tmpl")
csrf := c.Get("csrf").(string)
err := tpl.Execute(c.Response().Writer,
err := c.Render(
http.StatusOK,
"index.tmpl",
page{
AppName: setting.AppName(),
AppVer: appver,
@ -37,11 +37,16 @@ func Index() echo.HandlerFunc {
},
)
if err != nil {
log.Errorf("error when executing tmpl: '%q'", err)
return err
c.Logger().Errorf("error: %q", err)
return renderErrorPage(
c,
http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError),
err.Error(),
)
}
return nil
return err
}
}