agecem-org/server.go

57 lines
878 B
Go
Raw Normal View History

2023-02-17 17:28:47 -05:00
package main
import (
"embed"
"html/template"
"io"
2023-02-17 17:28:47 -05:00
"net/http"
"git.agecem.com/agecem/agecem-org/public"
2023-02-17 17:28:47 -05:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
2023-02-17 17:28:47 -05:00
)
// Types
type Template struct {
templates *template.Template
}
// Variables
var embedFS embed.FS
// Functions
func init() {
embedFS = public.GetEmbedFS()
}
2023-02-17 17:28:47 -05:00
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)
2023-02-17 17:28:47 -05:00
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)
}