A small, read-only Go service that serves the Bitcoin Calendar event databases over HTTP, in English and Russian.
It is read-only in a structural sense, not as a convention. The databases are an artifact
authored and validated in a separate repository and shipped here whole; this service opens
them with mode=ro, never migrates them, and never creates the indexes, triggers or
full-text tables they already carry. On the server the files are mode 0444 in a 0555
directory, and systemd's ReadOnlyPaths makes the kernel refuse a write even if a future
code change tried one. That arrangement exists because the project previously had eighteen
divergent copies of the same database and no way to tell which one any given consumer was
reading.
make build # CGO_ENABLED=1 go build -tags fts5 …
make test # black-box: builds the binary, serves a fixture, drives it over HTTP
DB_PATH_EN=/path/events_en.db \
DB_PATH_RU=/path/events_ru.db \
API_KEYS=some-secret \
./bitcal-api
curl localhost:3000/health | jq .
curl -H "X-API-KEY: some-secret" 'localhost:3000/api/events?month=8&day=9&lang=ru' | jq .Two things about the build are not optional:
-tags fts5. The SQLite driver does not compile FTS5 in by default, and without it every query touchingevents_ftsfails at runtime while the rest of the API looks fine. A build without the tag is refused outright — seefts5_required.go.- Build on Ubuntu/glibc, or in a matching container (
make build-ubuntu). CGO ties the binary to the C library it was built against; one built on macOS or Alpine will not start on the server at all.
Building requires Go 1.24 or newer.
Everything under /api requires an X-API-KEY header. /health, /public/v1/events and /public/v2/events do not.
| Endpoint | Purpose |
|---|---|
GET /health |
Which artifact this process has open, and whether it is fully indexed. Unauthenticated. |
GET /public/v2/events |
The v1 document plus each event’s stored url_path, for Calendar permalinks. Unauthenticated, unpaginated, with a version-specific strong ETag. |
GET /public/v1/events |
Every event for one language as a single document, for the website. Unauthenticated, unpaginated, with a strong ETag. |
GET /api/events |
Events, paginated. Filter with year, month, day, category, landmark. |
GET /api/events/:id |
One event. |
GET /api/events/tags/:tag |
Events carrying a tag. |
GET /api/tags |
Every tag with the number of events carrying it. |
GET /api/categories |
Every category with the number of events carrying it. |
GET /api/search?q= |
Full-text search over title, description and tags. Filter with category (repeatable) and landmark. |
All of them take lang=en (default) or lang=ru. Full detail, including every field and
every error, is in docs/APIDocumentation.md.
The public events endpoints need no key, because its consumer is a public
client the service cannot hand a secret to: the static website (gm-web) fetches it once
from Node at build time, and anyone else may read it the same way. It is not a browser
fetch, so no CORS origin needs to be added for it. It differs from /api/events on purpose:
- The whole artifact in one body, in the same order as
/api/events(date DESC, id DESC). No pagination. - A smaller event:
id,date,title,description,references,media. referencesandmediaare real arrays of strings,[]when absent — nevernull, never a JSON-encoded string. A malformed stored value is normalised to the strings it holds rather than dropping the event, and the top-levelinvalid_reference_fields/invalid_media_fieldscounters say how many fields that happened to. Strings are preserved as stored; deciding what is a URL is the consumer's job.schemaisbitcoin-calendar.public-events.v1, anddatabase.sha256/database.rowsare the same values/healthreports for that language.- Strong
ETagper service build, language and artifact;If-None-Matchanswers304. It changes when a new artifact is published or a new build of this service is deployed, since either can change the bytes.
lang behaves as everywhere else — en by default, unknown values fall back to en — and
the language field names the artifact actually served. This route and /health are
rate-limited by connecting IP, whatever X-API-KEY a caller sends: only under /api does
the key choose the bucket, because only there is it checked. Direct callers using the same
loopback address share one bucket; nginx-proxied callers all collapse into nginx's loopback bucket, because the app
sees nginx's address for every one of them — and that bucket overlaps the operator's direct
/health calls whenever they arrive from the same address. A public rollout therefore puts a cache in front of
this route (revalidating on the ETag) and owns the external per-client and aggregate
limits; the app limiter is not that protection. Exceeding the app limit is a 429, and a
genuine server fault a 500, as everywhere else.
These are the parts that are not guessable from the endpoint list. Each was a real bug.
dateis a string,"2013-08-09"— not a timestamp. The range starts at 1881-09-29, before the Unix epoch, and there is no time-of-day component to report. The column's declared type isdate, which makes the SQLite driver convert it to atime.Timebefore GORM sees it, sodatabase.gocarries a scanner that converts it back. Without that the API emits"1881-09-29T00:00:00Z"— an invented time and timezone.mediaandreferencesare JSON arrays encoded as strings, andnullwhen absent — never""and never"[]". Decode them a second time.nullmeans "no media", which is not the same claim as "an empty list of media".created_atandupdated_atare frequentlynull. Many rows genuinely have no timestamp. Rendering those as"0001-01-01T00:00:00Z"would be inventing data.url_path(/2013-08-09/hal-finneys-last-post/) is the cross-language join key and the website's page URL. It is present on every row.categoryis nottags[0]. Every event has exactly onecategory, and it is what the website colours and filters by. Tag order carries no meaning, so deriving it from the first tag is wrong. The tag and category vocabularies do not correspond at all:firstis a tag on ~104 rows and a category on none, andbitcoinis neither — so/api/events/tags/bitcoinreturns an empty list and?category=bitcoinis a400. Filter with/api/events?category=…and discover the values with/api/categories. The set is closed but owned by the data and liable to change in both directions — it was rewritten wholesale on 2026-08-12 — so accept unrecognised values rather than hardcoding the list. The service derives the accepted values from the artifact at startup for that reason; an unknown category is a400, not an empty list.landmarkis a boolean, orthogonal tocategory. It marks the events that matter to a bitcoiner — 402 of 581 RU and 394 of 565 EN — and drives one UI control, the "Только главное" switch. Filter with/api/events?landmark=true, which ANDs with?category=and the date filters. Alwaystrueorfalse, nevernull. Added 2026-08-12: an artifact published before then has no such column, and the service then reportsfalseeverywhere and rejects?landmark=with a400rather than answering a misleading empty list. It is a filter on/api/eventsand/api/search— sending it, orcategory, to/api/events/tags/:tagis a400too, rather than a200full of unfiltered results./api/searchtakescategorymore than once.?q=halving&category=tech&category=fiatmatches either category;landmarkANDs with that and withq. Both are validated exactly as on/api/events, filter before counting and paging — sototaland every page describe the filtered matches — and never narrow search to a date range. Results stay ordered by relevance, ties broken byiddescending.eventsis always an array,[]when nothing matches, on every endpoint that returns a list — and so isdataon/api/tagsand/api/categories. Nevernull.- An unknown
langsilently serves English.lang=xxis not an error. Do not rely on a typo being caught. /api/tagsreturns its list underdata, nottags.- A malformed
month,dayoryearis a 400, deliberately. An empty list is indistinguishable from a day that has no events, so a client with a bug in its date arithmetic would post nothing and report success forever. - A malformed search query is a 400, not a 500. Bare
AND/OR/NOT, unbalanced parentheses or quotes, and a leading*are all invalid FTS5. Prefix search (биткоин*) andOR/NEARdo work. - Quoting
qis a phrase search.q="bitcoin price"wants those words adjacent, in that order — 6 hits against the English artifact. Unquoted,q=bitcoin priceis an implicitANDand finds 39. limitis capped at 1000 andpageat 1000000, and both are a 400 when out of range or unparseable rather than being clamped. The ceiling sits above the corpus on purpose —limit=1000returns every event for a language — so it refuses only values that cannot be meant seriously.- Lists are newest first, ties broken by
iddescending. 19 dates carry more than one event in English, and without the tiebreaker paging across one could show an event twice and skip another. - Rate limiting under
/apiis 500/min per API key. Public and unauthenticated requests retain a 100/min per-IP limit. Give each consumer its own key: they all reach the service over loopback, so anything keyed per-IP would be one shared budget.
{
"status": "ok",
"version": "0.1.0-82cafb9",
"databases": {
"ru": {
"path": "/srv/bitcal/data/releases/20260813T054356Z/events_ru.db",
"sha256": "5bdc8c3e…",
"rows": 581,
"fts": { "indexed": 581, "consistent": true },
"categories": { "present": true, "count": 8 },
"landmark": { "present": true, "count": 402 }
}
}
}path is symlink-resolved and sha256 is computed once at startup, so this describes the
inode the process actually has open rather than whatever current points at when you ask.
Those two differing is the failure the endpoint exists to catch.
fts.consistent is indexed == rows: every event is reachable by search. When it is false,
status becomes degraded — the service is up and search is silently incomplete. status
reports full-text coverage only; the two blocks below never affect it, because serving an
artifact that predates a column is what a rollback looks like.
categories is what the service read out of the artifact at startup, and it is what
?category= validates against. count: 0 means every category filter is rejected — either
the artifact predates the column (present: false) or no row carries a value (present: true, which should never have been published; publish-db.sh refuses to leave a release in
that state).
landmark reports the same two things for the flag, and count is exactly what
?landmark=true returns. It differs in what count: 0 means: no row carrying the flag is
legal data — the validator sets no target fraction for an editorial judgement — so
?landmark=true answers an empty list and publish-db.sh warns rather than refusing.
The service refuses to start if a full-text index is missing, empty or unreadable. That
is deliberate: a broken index makes /api/search return an empty result set, which is
indistinguishable from a query that matched nothing, so nothing downstream could ever report
it. Startup is the only place it can be made loud.
A native systemd service, not Docker. The unit is deploy/bitcal-api.service; it binds
loopback only and is not proxied by nginx.
There are two release paths and they do not overlap:
deploy/publish-db.shships database artifacts. It validates the source, stages it, validates the staged copy again, checks that this API can actually emit the staged schema, flips thecurrentsymlink, restarts the service — mandatory, since SQLite holds an open file descriptor and the symlink alone changes nothing — then verifies/health.deploy/publish-api.shships the binary. It builds on the box (CGO ties the binary to the target's glibc), runs the suite there, backs the running binary aside, installs, restarts, and asserts/healthshows a new version and unchanged data.
Both roll back automatically if anything after the irreversible step fails. Because they are
independent, the binary and the data drift; check both halves of /health when diagnosing.
See docs/Deployment.md.
The suite lives in tests/ and is black-box: it builds this binary, stages a database fixture
exactly as a release is staged (0444 in a 0555 directory), starts the service against it
and drives it over HTTP. So make test also exercises the build tag, the read-only open, the
boot probe and the JSON contract above — none of which a unit test calling InitDB directly
would prove.
- docs/APIDocumentation.md — every endpoint, field and error
- docs/DatabaseDocumentation.md — schema and the artifact contract
- docs/Deployment.md — building, installing, releasing, troubleshooting
| Variable | |
|---|---|
API_KEYS |
Required. Comma-separated. The service exits if unset. |
DB_PATH_EN |
Required. No default — the service exits naming the variable. |
DB_PATH_RU |
Required. Same. |
LISTEN_ADDR |
Defaults to 127.0.0.1:3000. |
CORS_ALLOWED_ORIGINS |
Comma-separated. Defaults to http://localhost:3000. |
The API will be publicly available in Q3 2026. To test it before then, DM @Tony on Nostr and I'll share a key.
GET /public/v2/events?lang=ru returns schema bitcoin-calendar.public-events.v2.
It keeps v1's envelope, normalization, ordering, language fallback and cache semantics,
adding url_path to each event verbatim from storage (for example,
/2013-08-09/hal-finneys-last-post/). Consumers build localized links under
https://bitcoin-calendar.org/ru/events/, encoding the date and slug as separate
path segments. Do not reconstruct the stored path from the historical date or title.
V1 stays available with its original event shape; v1 and v2 have distinct ETags.
Roll out the API before updating gm-web. The public reverse proxy/cache must expose
/public/v2/events with the same protections as v1. Verify an unauthenticated 200,
the v2 schema and a populated url_path through the public origin before the gm-web
release; deploying gm-web first would omit its history section until v2 is available.
Optional articles / event_articles tables carry independently published Markdown
articles and local event relations. Authenticated GET /api/articles?lang=ru returns
published summaries, GET /api/articles/:slug?lang=ru returns a full article with
related events and verified published translations, and GET /api/events/:id/articles
returns a primary article or null plus extra summaries. Drafts are never exposed.
These additive routes do not change public event documents or event search.
Old artifacts remain readable; article routes return 503 if the optional schema is
missing or incomplete. The service performs no schema migration. The release schema
guard also compares the article tables, constraints and relation indexes when present.
Article detail may include an optional metadata JSON object containing editorial
title, description and image (url, alt, width, height, credit).
Legacy article artifacts without this nullable column remain supported. Metadata
is independent of historical event dates and is omitted from article summaries.