commit b3a730b3dd6ae7d3c8b59cbf8c15a03c2684ca33 Author: Grail Finder (aider) Date: Thu May 1 17:07:15 2025 +0300 feat: add initial Go+HTMX web project structure diff --git a/cmd/web/main.go b/cmd/web/main.go new file mode 100644 index 0000000..e526d54 --- /dev/null +++ b/cmd/web/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "net/http" + "os" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +func main() { + r := chi.NewRouter() + r.Use(middleware.Logger) + + // Setup routes + r.Get("/", handleHome) + + port := ":3000" + fmt.Printf("Starting server on %s\n", port) + err := http.ListenAndServe(port, r) + if err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3d40e45 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module myhtmxapp + +go 1.21 + +require ( + github.com/go-chi/chi/v5 v5.0.12 + github.com/go-chi/render v1.0.3 +) diff --git a/handlers/handlers.go b/handlers/handlers.go new file mode 100644 index 0000000..8210bf5 --- /dev/null +++ b/handlers/handlers.go @@ -0,0 +1,11 @@ +package handlers + +import ( + "html/template" + "net/http" +) + +func HandleHome(w http.ResponseWriter, r *http.Request) { + tmpl := template.Must(template.ParseFiles("templates/public/index.html")) + tmpl.Execute(w, nil) +} diff --git a/templates/public/index.html b/templates/public/index.html new file mode 100644 index 0000000..1f5f8e4 --- /dev/null +++ b/templates/public/index.html @@ -0,0 +1,13 @@ + + + + + + HTMX + Go Starter + + + +

HTMX + Go Starter

+

Edit this HTML in templates/public/index.html

+ +