initial commit. Go test app

This commit is contained in:
2026-05-04 16:38:32 +02:00
parent e50565bf85
commit e1a58e92a8
7 changed files with 329 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
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"))
}