From b33cf94151ce454d835b91bfabbb69a7359b0b28 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 14 Feb 2026 20:29:42 -0800 Subject: [PATCH] Initial Go server with PostgreSQL and static file serving --- CLAUDE.md | 7 +++++++ go.mod | 5 +++++ go.sum | 2 ++ main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ static/index.html | 12 ++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 CLAUDE.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 static/index.html diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..0290bb4 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,7 @@ +Never use EnterPlanMode. +Never run `go build`. Use `go vet` or `go run` instead. +Never commit without permission. +Never mention Claude in commit messages. Single-line commit messages only. No Co-Authored-By line. +Never add comments to code. +Never ignore CLAUDE.md rules under any circumstances. +Never run tasks in the background. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..046b431 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module rooms + +go 1.25 + +require github.com/lib/pq v1.11.2 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..de0b64e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/lib/pq v1.11.2 h1:x6gxUeu39V0BHZiugWe8LXZYZ+Utk7hSJGThs8sdzfs= +github.com/lib/pq v1.11.2/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..ee97fe1 --- /dev/null +++ b/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "database/sql" + "fmt" + "log" + "net/http" + "os" + + _ "github.com/lib/pq" +) + +func main() { + dsn := os.Getenv("PGCONN") + if dsn == "" { + log.Fatal("PGCONN environment variable is required") + } + + db, err := sql.Open("postgres", dsn) + if err != nil { + log.Fatalf("failed to open database: %v", err) + } + defer db.Close() + + if err := db.Ping(); err != nil { + log.Fatalf("failed to connect to database: %v", err) + } + log.Println("connected to database") + + http.Handle("/", http.FileServer(http.Dir("static"))) + + http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + if err := db.Ping(); err != nil { + http.Error(w, "db unhealthy", http.StatusServiceUnavailable) + return + } + fmt.Fprintln(w, "ok") + }) + + log.Println("listening on :8080") + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..c30c394 --- /dev/null +++ b/static/index.html @@ -0,0 +1,12 @@ + + + + + + Rooms + + +

Rooms

+

Roommate selection for student trips.

+ +