package main import ( "github.com/labstack/echo/v4" ) func main() { db := InitDB() e := echo.New() // Route: View all tasks e.GET("/", func(c echo.Context) error { var tasks []Task db.Find(&tasks) // Render the full page return Page(tasks).Render(c.Request().Context(), c.Response().Writer) }) // Route: Add a new task (Called by HTMX) e.POST("/tasks", func(c echo.Context) error { title := c.FormValue("title") db.Create(&Task{Title: title}) var tasks []Task db.Find(&tasks) // HTMX only needs the updated TaskList, not the whole page! return TaskList(tasks).Render(c.Request().Context(), c.Response().Writer) }) e.Logger.Fatal(e.Start(":8080")) }