package main import ( "errors" "fmt" "io" "text/template" "gitea.elara.ws/Hazel/hangman/internal/rest_handler" "gitea.elara.ws/Hazel/hangman/internal/view_handler" "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 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")) templates["create_user"] = template.Must(template.ParseFiles("templates/create_user.html", "templates/base.html")) e.Renderer = &TemplateRegistry{ templates: templates, } e.POST("/api/session", rest_handler.CreateSession) e.POST("/api/:session/user", rest_handler.CreateUser) e.POST("/api/:session/test-auth", rest_handler.TestAuth) e.POST("/api/:session/guess", rest_handler.GuessLetter) e.GET("/", view_handler.CreateSession) e.GET("/:name", view_handler.CreateUser) e.Logger.Fatal(e.Start(":1323")) }