feat: add initial Go+HTMX web project structure

This commit is contained in:
Grail Finder (aider)
2025-05-01 17:07:15 +03:00
commit b3a730b3dd
4 changed files with 58 additions and 0 deletions

26
cmd/web/main.go Normal file
View File

@ -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)
}
}

8
go.mod Normal file
View File

@ -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
)

11
handlers/handlers.go Normal file
View File

@ -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)
}

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTMX + Go Starter</title>
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
</head>
<body>
<h1>HTMX + Go Starter</h1>
<p>Edit this HTML in templates/public/index.html</p>
</body>
</html>