tijl.dev-core/cmd/server/main.go
tijl 4c640fb3b3
Some checks failed
build / build (push) Failing after 0s
updates
2024-08-20 11:49:05 +02:00

48 lines
1.0 KiB
Go

package main
import (
"html/template"
"log"
"net/http"
"git.tijl.dev/tijl/tijl.dev/internal/assets"
"git.tijl.dev/tijl/tijl.dev/internal/i18n"
"git.tijl.dev/tijl/tijl.dev/static"
"git.tijl.dev/tijl/tijl.dev/views"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/template/html/v2"
)
func main() {
assets.LoadSVGs()
i18n.LoadTranslations()
engine := html.NewFileSystem(http.FS(views.Embed), ".html")
engine.AddFunc("icon", assets.Svg)
// Todo better language system
engine.AddFunc("translate", func(key string) template.HTML {
translations := i18n.GetTranslations()["en"] // for now we just fix it to english
if translation, ok := translations[key]; ok {
return template.HTML(translation)
}
return ""
})
app := fiber.New(fiber.Config{
Views: engine,
})
app.Get("/", func(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{})
})
app.Use("/static", filesystem.New(filesystem.Config{
Root: http.FS(static.Embed),
}))
log.Fatal(app.Listen(":3000"))
}