HTTP server that returns the current forecast and temperature classification for a given location using the National Weather Service API.
- Go 1.26+ — install from https://go.dev/dl/
make build-checkmake testmake runServer starts on port 8080 by default. Override with:
make run PORT=9090Logs full NWS raw response bodies at DEBUG level:
make run-debug # raw JSON output
make run-debug-jq # pretty-printed via jq (requires jq installed)Plano, TX:
curl "http://localhost:8080/weather?lat=33.019844&lon=-96.698883"El Segundo, CA (2 hours behind Plano, TX — good edge case):
curl "http://localhost:8080/weather?lat=33.9192&lon=-118.4165"Fairbanks, AK (extreme cold edge case):
curl "http://localhost:8080/weather?lat=64.8401&lon=-147.7164"Response:
{
"forecast": "Mostly Cloudy",
"temperature_classification": "moderate"
}forecast— short forecast string from NWS (periods[0].shortForecast)temperature_classification—very hot(>=100°F),hot(>=85°F),cold(<=55°F),very cold(<=30°F), ormoderateperiods[0]is always the active NWS period for the location's local time — pre-dawn returns "Overnight", not "Today"
Per-IP rate limiter: 5 req/sec, burst of 10. Start the server first (make run), then fire 20 concurrent requests against /health (instant response, no NWS latency) to observe the burst limit:
for i in $(seq 1 20); do curl -s -o /dev/null -w "%{http_code}\n" "http://localhost:8080/health" & done; waitFirst 10 return 200, remainder return 429 Too Many Requests.
Also, observable with the actual weather endpoint (NWS latency spreads responses but 429s still appear):
for i in $(seq 1 20); do curl -s -o /dev/null -w "%{http_code}\n" "http://localhost:8080/weather?lat=33.019844&lon=-96.698883" & done; waitcurl http://localhost:8080/healthEnable pre-commit hooks (Go version check, fmt, fix-diff, lint):
git config core.hooksPath .githooksRun checks manually:
make fmt-diff # show formatting diff
make fix-diff # show go fix changes
make lint # golangci-lintVersion 0.1 — work in progress.