You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Build & Run
6
+
7
+
```bash
8
+
# Windows local dev (build + run, loads .env automatically):
9
+
build.bat
10
+
11
+
# Quick restart (skip rebuild):
12
+
run.bat
13
+
14
+
# Build only:
15
+
go build -o moon.exe
16
+
17
+
# Linux production binary (required for Linode deploy — must be static):
18
+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o moon .
19
+
```
20
+
21
+
Requires a `.env` file with `GOOGLE_MAPS_API_KEY`. See `.env.example`.
22
+
23
+
## Tests
24
+
25
+
```bash
26
+
go test -v ./...
27
+
```
28
+
29
+
Tests use `httptest` against handlers directly. Templates must be present in the working directory (they're parsed via `template.ParseGlob("*.html")` at init).
30
+
31
+
## Deployment
32
+
33
+
Push to `master` triggers GitHub Actions: runs tests, builds static Linux binary, SCPs to Linode, runs `deploy-moon` script. No manual deploy steps needed.
34
+
35
+
The deploy script (`scripts/deploy-moon`) stops the service, replaces the binary (must `rm -f` first to avoid "text file busy"), copies web assets, restarts. It has self-update logic.
36
+
37
+
## Architecture
38
+
39
+
Single-file Go server (`moon.go`) with no framework. All handlers, middleware, and `main()` live in one file.
40
+
41
+
**Request flow:**`main()` → `makeHTTPServer()` → `http.ServeMux` with middleware chain: `requestLogger(securityHeaders(mux))`. Static assets get an additional `cacheStaticAssets` wrapper.
42
+
43
+
**Routes:**
44
+
-`/` — home page with Google Maps, geolocation, moon rise/set display
45
+
-`/about` — static about page
46
+
-`/calendar` — full-month table of sun/moon rise/set times; server-rendered with `year`/`month`/`lat`/`lon`/`zon` query params
47
+
-`/gettimes` — JSON API returning `riseset.RiseSet` for given `lon`/`lat`/`zon`
48
+
-`/static/` — CSS, JS, background image
49
+
50
+
**Templates:** Go `html/template` files at project root (`index.html`, `about.html`, `calendar.html`). Parsed once at init, with fallback to on-demand parsing. Google Maps API key is injected server-side into `index.html` (not exposed via JS endpoint).
51
+
52
+
**Key dependency:**`github.com/exploded/riseset` — calculates rise/set times. Pinned to a pseudo-version commit hash in `go.mod`. Update with `go get github.com/exploded/riseset@<commit>`.
53
+
54
+
**Frontend:** Vanilla JS + jQuery 3.7.1. `static/script.js` handles Google Maps (AdvancedMarkerElement), geolocation, timezone auto-detection, and AJAX calls to `/gettimes`. The `updateCalLink()` function keeps the calendar link in sync with current lat/lon/zon.
55
+
56
+
**riseset API caveat:** Always check `AlwaysAbove`/`AlwaysBelow` before displaying `Rise`/`Set` values. Rise/Set are empty strings when the moon never rises or never sets.
0 commit comments