48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"text/template"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type TemplateRegistry struct {
|
|
templates map[string]*template.Template
|
|
}
|
|
|
|
// Implement e.Renderer interface
|
|
func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
|
tmpl, ok := t.templates[name]
|
|
if !ok {
|
|
err := errors.New("Template not found -> " + name)
|
|
return err
|
|
}
|
|
return tmpl.ExecuteTemplate(w, "base.html", data)
|
|
}
|
|
|
|
func CreateSessionHandler(c echo.Context) error {
|
|
return c.Render(http.StatusOK, "create_session", map[string]interface{}{
|
|
"name": "create session",
|
|
})
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println("wanna play hangman? Well ya cant since it isn't implemented yet..")
|
|
|
|
e := echo.New()
|
|
|
|
templates := make(map[string]*template.Template)
|
|
templates["create_session"] = template.Must(template.ParseFiles("templates/create_session.html", "templates/base.html"))
|
|
e.Renderer = &TemplateRegistry{
|
|
templates: templates,
|
|
}
|
|
|
|
e.GET("/", CreateSessionHandler)
|
|
|
|
e.Logger.Fatal(e.Start(":1323"))
|
|
}
|