# health-bridge-go

Minimal Rust-inspired performance spike: Go port of health-bridge Python API.

## Purpose

Compare latency/throughput of Go + SQLite vs Python FastAPI for the health-bridge ingestion API.

## What's Ported

- `/health` - Simple health check endpoint
- `/` - Root endpoint  
- `/ingest_signed` - HMAC-verified ingestion with nonce replay protection
- `/summary` - Read daily summaries (requires Bearer token auth)

## What's Intentionally Skipped

- Full SQLite schema migrations from Python version
- `/overview`, `/debug/day`, `/rebuild-summary` endpoints
- Complex record normalization and deduplication
- CORS middleware (not needed for local benchmark)
- Nonce table cleanup thread
- Multiple subject handling complexity

## Quick Start

```bash
# Build
go build -o health-bridge-go .

# Run (defaults to port 18007)
HEALTH_BRIDGE_SIGNED_INGEST_SECRET=your-secret HEALTH_BRIDGE_TOKEN=changeme ./health-bridge-go

# Or with custom port
PORT=18007 DB_PATH=~/health-bridge-go/health.db ./health-bridge-go
```

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `PORT` | `18007` | Server port |
| `DB_PATH` | `$HOME/health-bridge-go/health.db` | SQLite database path |
| `HEALTH_BRIDGE_TOKEN` | `changeme` | Bearer token for /summary |
| `HEALTH_BRIDGE_SIGNED_INGEST_SECRET` | (empty) | HMAC secret for /ingest_signed |
| `HEALTH_BRIDGE_SIGNED_INGEST_DEVICE` | `pixel9a-chicho` | Expected device header |
| `HEALTH_BRIDGE_SIGNED_INGEST_MAX_SKEW_SECONDS` | `300` | Timestamp validation window |
| `HEALTH_BRIDGE_DEFAULT_SUBJECT` | `chicho` | Default subject for records |

## Benchmark

```bash
chmod +x benchmark.sh
./benchmark.sh
```

Requires both Python server (port 3007) and Go server (port 18007) running.

## Stack

- Go 1.26
- chi router v5 (minimal routing)
- modernc.org/sqlite (pure Go, no CGO)
- stdlib net/http

## Notes

- Uses WAL journal mode for better concurrent reads
- Single SQLite connection (serialized writes)
- No connection pooling (SQLite limitation)