123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package fiber
- import (
- "errors"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html/v2"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/mapper"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/templates/functions"
- )
- func getViewsEngine(sp ServiceProvider) *html.Engine {
- engine := html.New(templatesPath, ".html")
- engine.AddFunc("now", functions.Now)
- engine.AddFunc("noescape", functions.NoEscape)
- engine.AddFunc("concat", functions.Concat)
- engine.AddFunc("gridsep", functions.GridSep)
- engine.AddFunc("version", functions.Version(sp))
- engine.AddFunc("trans", functions.Trans)
- engine.AddFunc("link", functions.Link)
- return engine
- }
- func getErrorHandler() fiber.ErrorHandler {
- return func(fctx *fiber.Ctx, err error) error {
- lang := mapper.LanguageFromContext(fctx)
- errCode := fiber.StatusInternalServerError
- var e *fiber.Error
- if errors.As(err, &e) {
- errCode = e.Code
- }
- var renderData fiber.Map
- if errCode == fiber.StatusNotFound {
- renderData = fiber.Map{
- "pageTitle": i18n.T(lang, "page_not_found_err_title"),
- "code": fiber.StatusNotFound,
- "text": i18n.T(lang, "page_not_found_err_desc"),
- }
- } else {
- renderData = fiber.Map{
- "pageTitle": i18n.T(lang, "internal_err_title"),
- "code": fiber.StatusInternalServerError,
- "text": i18n.T(lang, "internal_err_desc"),
- }
- }
- renderData["headTitle"] = i18n.T(lang, "head_title")
- return fctx.Render("error", renderData, "_layout")
- }
- }
|