| author | 2025-08-18 18:49:21 +0700 | |
|---|---|---|
| committer | 2025-08-18 18:49:21 +0700 | |
| commit | f3b5c8136217fd57f7ae948a153f3510558a139d (patch) | |
| tree | e275408d111e0fd98f46826ca6cabba6aafdd763 /internal/router/root.go | |
| parent | 1a0abbb6439690fb9167dce5ecb800dc5c41e130 (diff) | |
| download | web-f3b5c8136217fd57f7ae948a153f3510558a139d.tar.gz web-f3b5c8136217fd57f7ae948a153f3510558a139d.zip | |
refactor: have routes in separate files
Diffstat (limited to 'internal/router/root.go')
| -rw-r--r-- | internal/router/root.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/router/root.go b/internal/router/root.go new file mode 100644 index 0000000..f5be6cb --- /dev/null +++ b/internal/router/root.go @@ -0,0 +1,24 @@ +package router + +import ( + "log/slog" + + "github.com/SayaAndy/saya-today-web/config" + "github.com/SayaAndy/saya-today-web/internal/templatemanager" + "github.com/gofiber/fiber/v2" +) + +func Root(tm *templatemanager.TemplateManager, localeCfg []config.AvailableLanguageConfig) func(c *fiber.Ctx) error { + return func(c *fiber.Ctx) error { + content, err := tm.Render("index", fiber.Map{ + "AvailableLanguages": localeCfg, + }) + if err != nil { + slog.Warn("failed to generate page", slog.String("page", "/"), slog.String("error", err.Error())) + c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) + return c.Status(fiber.ErrInternalServerError.Code).SendString("failed to generate page") + } + + return c.Type("html").Send(content) + } +} |