web

CircleCI codecov Go Reference Stability: Active

🌐 Web

A small Go service that serves the website at:

The service is built on top of the mvc package from go-service and ships as a single binary with server-side templates, content, the favicon, and static site assets embedded.

🧭 Background

This project is an implementation playground for the ideas outlined in:

✨ What it does

At a high level the service:

The HTML templates, error templates, books YAML data, favicon image, robots file, and sitemap are embedded into the binary using go:embed. Full-page browser rendering loads HTMX and selected daisyUI 5.8.0 CSS components with the Silk theme from jsDelivr. All CDN resources are pinned with integrity hashes. Stylesheets are loaded individually to avoid combined CDN CSS source maps that DevTools would fetch outside the CSP’s connect-src allowlist. The full layout includes the site’s responsive styles; no frontend build step or additional JavaScript runtime is required.

The home page uses an editorial layout with system fonts, and the books page presents recommendations as responsive cards with localized “View book” links.

🏗️ Architecture overview

🗂️ Project layout

This repo follows the structure described in:

Key directories:

🧩 Dependency injection and modules

The service is wired with dependency injection using go-signal/v2. The top-level module that assembles the server is:

It pulls in configuration, health, and site modules.

🛣️ MVC routing and rendering

Routing and rendering are handled using:

Feature modules (e.g. books/root/robots/sitemap) register their routes during DI wiring.

🌍 Localization

Full pages, partial renders, and not-found pages select English, German, or Spanish from the request’s Accept-Language header. English is the default when the header is absent, invalid, or unsupported. Regional preferences such as de-CH and es-MX match the corresponding supported language.

curl -i -H 'Accept-Language: de' http://localhost:11000/books
curl -i -X PUT -H 'Accept-Language: es' http://localhost:11000/books

Localized HTML responses include Content-Language and Vary: Accept-Language; full pages also set <html lang> to the selected language. Page metadata, navigation, page text, book topics and recommendation notes, and the footer are translated. Book titles, author names, links, and static assets retain their original values.

Messages live in internal/site/locales/active.{en,de,es}.yaml and are embedded in the binary. site.NewCatalog loads them during startup, so invalid catalogs or message template syntax prevent startup. MVC supplies .Localizer to each template; .Localizer.Text resolves message IDs, and .Localizer.Message supplies variables such as the footer year and version. Missing translations fall back to English. Missing message IDs or invalid message variables fail rendering. Templates escape localized text as HTML.

📦 Embedded assets

The site package embeds:

See:

🔌 Endpoints

📄 Pages

[!NOTE] The PUT endpoints exist to support partial rendering patterns, for example HTMX-style incremental updates. The exact response shape depends on the templates/layout configured in the MVC layer.

[!TIP] Use GET when checking complete pages in a browser and PUT when checking fragment rendering.

🫀 Health and observability

The HTTP transport registers service-prefixed health and observability routes. With the local service name web, the endpoints are:

Health timings are configured via the service config under the health section.

/web/metrics is registered only when metrics are enabled with telemetry.metrics.kind: prometheus, as in the local config. Disabled or OTLP metrics do not expose that route.

/web/healthz uses the default go-health/v2 online registration. It checks https://google.com/generate_204, https://cp.cloudflare.com/generate_204, and https://connectivity-check.ubuntu.com concurrently, and reports healthy when any one responds with 200 OK or 204 No Content. Restricted public connectivity can therefore affect overall health. /web/livez and /web/readyz use noop checks.

🛡️ Response headers

Site responses include browser security headers such as Content-Security-Policy, X-Content-Type-Options, Referrer-Policy, X-Frame-Options, Permissions-Policy, and Strict-Transport-Security.

The CSP permits the site’s own stylesheet, jsDelivr for HTMX and daisyUI CSS, and Cloudflare Insights script and beacon origins (static.cloudflareinsights.com and cloudflareinsights.com) for production browser analytics.

The static routes /robots.txt, /sitemap.xml, and /favicon.ico return Cache-Control: public, max-age=3600. Clients can reuse the response for one hour. The MVC handler serves the full asset on each successful GET request.

MVC applies the same cache policy to /assets/site.css. Full pages link to the stylesheet with its SHA-256 fingerprint in the v query parameter. A mismatch returns 404 with Cache-Control: no-store. During a rolling deployment, every replica that can receive a stylesheet request needs to serve the fingerprint linked by the page.

[!NOTE] The acceptance suite verifies security headers across page, static-asset, and not-found responses. It also checks the static cache policy and follows the fingerprinted stylesheet link advertised by the page.

🧰 Development

✅ Prerequisites

Install:

If you are cloning the repo, initialize submodules before relying on Make targets:

[!IMPORTANT] The required bin submodule uses a GitHub SSH URL. Configure GitHub SSH access before running the recursive clone or submodule update commands.

git clone --recurse-submodules https://github.com/alexfalkowski/web.git

For an existing checkout where bin/ may be absent or stale:

git submodule sync
git submodule update --init

Then install dependencies:

make dep

[!IMPORTANT] The root Makefile includes shared build fragments from bin/, so a missing submodule can prevent make from parsing at all. Once bin/ is present, make submodule can refresh it through the normal repo target.

[!WARNING] Some targets require external tools in addition to Go and Ruby. For example, make dev uses air, Go checks may use gotestsum, golangci-lint, and govulncheck, and security checks may use Trivy.

🧾 Useful Make targets

This repo relies on make for a consistent developer experience.

List all available commands:

make help

Common workflows:

# Install dependencies (Go + Ruby)
make dep

# Run linters
make lint

# Auto-fix lint where possible
make fix-lint

# Format code
make format

# Run the repo-defined Go specs wrapper
make specs

# Run Cucumber acceptance tests
make features

# Run Cucumber benchmark scenarios
make benchmarks

[!TIP] make help is the best way to discover the current command surface because most project workflows come from the shared bin/ Make fragments.

🚀 Running locally

There are two common ways to run the service:

🔁 1) Dev mode

Use the dev target (recommended while iterating):

make dev

This runs the service with test/.config/server.yaml.

🧱 2) Build and run the binary

Build a local binary:

make build

Then run it:

./web server -config file:test/.config/server.yaml

[!IMPORTANT] The current config flag is -config; -c is the short form. The CLI command is server, registered in internal/cmd, and starts the HTTP server using the DI module graph.

🔎 Example: verifying endpoints

Once the server is running, you can verify key endpoints.

If you started the service with make dev or with -config file:test/.config/server.yaml, the HTTP server listens on localhost:11000.

Pages:

curl -i http://localhost:11000/
curl -i http://localhost:11000/books
curl -i http://localhost:11000/robots.txt
curl -i http://localhost:11000/sitemap.xml
curl -i http://localhost:11000/favicon.ico

Partial renders (PUT):

curl -i -X PUT http://localhost:11000/
curl -i -X PUT http://localhost:11000/books

Health:

curl -i http://localhost:11000/web/healthz
curl -i http://localhost:11000/web/livez
curl -i http://localhost:11000/web/readyz
curl -i http://localhost:11000/web/metrics

Not found:

curl -i http://localhost:11000/not-a-real-page

[!CAUTION] Ports, TLS, telemetry, and other server settings come from configuration. Do not treat test/.config/server.yaml as a production configuration.

⚙️ Configuration

The service config model lives in:

It embeds the shared base config from go-service and adds a health section.

The canonical local example is:

The -config flag (short form -c) accepts these source routes:

The local development config in test/.config/server.yaml includes this first-use excerpt:

health:
  duration: 1s
  timeout: 1s
transport:
  http:
    address: tcp://:11000

The service-specific health section is required. health.duration must be a positive Go duration and controls how often health registrations are evaluated; health.timeout may be zero or greater and controls the online health check timeout. A zero timeout selects the go-health/v2 default of 30 seconds.

[!NOTE] The full local config also sets the environment, UUID generation, tint logging, Prometheus metrics, an OTLP tracer endpoint, HTTP limiter tokens/interval, and HTTP timeout. The wider configuration shape comes from shared go-service sections such as environment, telemetry, transport, and version metadata.

🧪 Testing

The primary behavioral checks are the Ruby/Cucumber suites:

make features
make benchmarks

These targets run the acceptance harness from test/. Nonnative loads test/nonnative.yml, starts ../web server -config file:.config/server.yaml on localhost:11000, and writes Nonnative, server, and Cucumber output under test/reports/. Stop any local service already using 11000 before running the acceptance suites.

To run a narrower acceptance scope while iterating, pass feature paths relative to test/:

make features feature=features/site/site.feature
make features feature=features/health/observability.feature
make benchmarks feature=features/site/benchmark.feature

The main CircleCI service build also runs:

make lint
make sec
make analyse
make coverage
make codecov-upload

make codecov-upload is CI upload behavior, not a read-only local validation step.

The full CircleCI workflow additionally runs Docker image checks and the submodule sync/push job on non-master branches:

make platform=amd64 test-docker
make platform=arm64 test-docker
make sync push

On master, CircleCI also runs versioning, Docker release/manifest, and deploy jobs.

Go support checks are still available:

make specs
go test ./...

[!NOTE] Treat make features and make benchmarks as the authoritative product behavior checks. The Go tests support build/tooling confidence but are not the main product signal.

💎 Ruby acceptance test client

The Ruby test helper client is in:

It provides a small wrapper around HTTP calls used by the acceptance tests.

🎨 Style

Go code generally follows:

🚢 Changes and releases

Releases are handled through CI and GoReleaser configuration:

Generated changelog text is part of the GoReleaser release flow.

[!CAUTION] Release, Docker publishing, deployment, and GitHub PR targets can push to external systems. Use the read-only validation targets unless you intend to publish or update remote state.

📜 License

See: