agecem-org/server.go
Victor Lacasse-Beaudoin 1022dd05db Ajouter templating go
Déplacer embed/ vers public/

Ajouter public/js et public/scss

Ajouter templating pour public/html/*.gohtml

Ajouter --build à procédure dans README.md

Déplacer contenu de index.html vers template `index-html`

Ajouter middleware RemoveTrailingSlash

Déplacer anonymous function de route `/` vers handler `handleIndex`
2023-03-21 18:37:51 -04:00

56 lines
878 B
Go

package main
import (
"embed"
"html/template"
"io"
"net/http"
"git.agecem.com/agecem/agecem-org/public"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
// Types
type Template struct {
templates *template.Template
}
// Variables
var embedFS embed.FS
// Functions
func init() {
embedFS = public.GetEmbedFS()
}
func Execute() {
e := echo.New()
t := &Template{
templates: template.Must(template.ParseFS(embedFS, "html/*.gohtml")),
}
e.Renderer = t
e.Pre(middleware.RemoveTrailingSlash())
e.GET("/", handleIndex)
e.Logger.Fatal(e.Start(":8080"))
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
// API Handlers
// HTML Handlers
func handleIndex(c echo.Context) error {
return c.Render(http.StatusOK, "index-html", nil)
}