Initial Go server with PostgreSQL and static file serving

This commit is contained in:
Ian Gulliver
2026-02-14 20:29:42 -08:00
commit b33cf94151
5 changed files with 68 additions and 0 deletions

7
CLAUDE.md Normal file
View File

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

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module rooms
go 1.25
require github.com/lib/pq v1.11.2

2
go.sum Normal file
View File

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

42
main.go Normal file
View File

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

12
static/index.html Normal file
View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rooms</title>
</head>
<body>
<h1>Rooms</h1>
<p>Roommate selection for student trips.</p>
</body>
</html>