web

command module
v2.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

CircleCI codecov Go Reference

🌐 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:

  • serves the home page (/)
  • serves a books page (/books)
  • serves robots.txt (/robots.txt)
  • serves sitemap.xml (/sitemap.xml)
  • serves the favicon (/favicon.ico)
  • renders a custom not-found page for missing routes
  • adds browser security headers to site responses
  • exposes health, liveness/readiness, and metrics endpoints

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:

  • main.go: entrypoint for the web binary
  • internal/: application code (not importable from other modules)
  • test/: acceptance/system tests and supporting Ruby test client
  • bin/ + Makefile: build/dev/test automation
🧩 Dependency injection and modules

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

  • internal/cmd.Module

It pulls in configuration, health, and site modules.

πŸ›£οΈ MVC routing and rendering

Routing and rendering are handled using:

  • go-service/v3/net/http/mvc

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:

  • templates for layout, pages, and not-found errors
  • the first-party stylesheet at internal/site/root/layout/site.css
  • English, German, and Spanish message catalogs
  • the books YAML file used to render the books page
  • the favicon PNG
  • robots.txt
  • sitemap.xml

See:

  • internal/site/site.go

πŸ”Œ Endpoints

πŸ“„ Pages
  • GET / renders the home page
  • PUT / renders a partial/fragment version of the home page (used for incremental updates)
  • GET /books renders the books page
  • PUT /books renders a partial/fragment version of the books page
  • GET /robots.txt serves the robots file as a static asset
  • GET /sitemap.xml serves the sitemap file as a static asset
  • GET /favicon.ico serves the browser favicon
  • GET /assets/site.css serves the embedded stylesheet
  • missing routes render a 404 not-found page

[!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:

  • /web/healthz (overall health / online)
  • /web/livez (liveness)
  • /web/readyz (readiness)
  • /web/metrics (Prometheus metrics)

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:

  • Go (see go.mod; check locally with go version)
  • Ruby
  • Bundler for the Ruby test harness
  • GNU Make 4 or newer (gmake on macOS when /usr/bin/make is incompatible)

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:

  • internal/config.Config

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

The canonical local example is:

  • test/.config/server.yaml

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

  • file:<path> loads a file and selects its decoder from the extension.
  • env:<ENV_VAR> loads an environment variable whose value has the form <extension>:<base64-content> (for example, yaml:...).
  • Omitting the flag uses default lookup for web.{yaml,yml,hjson,toml,json} in the executable directory, the user config directory under web/, and /etc/web/. This lookup requires HOME or XDG_CONFIG_HOME; use an explicit source when neither is available.

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:

  • test/lib/web.rb
  • test/lib/web/v1/http.rb

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:

  • .circleci/config.yml
  • .goreleaser.yml

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:

  • LICENSE

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
internal
cmd
Package cmd wires up the service's CLI commands.
Package cmd wires up the service's CLI commands.
config
Package config defines the configuration model for the web service.
Package config defines the configuration model for the web service.
health
Package health configures and exposes health and liveness/readiness endpoints.
Package health configures and exposes health and liveness/readiness endpoints.
site
Package site wires the HTTP site (routes, views, and embedded assets).
Package site wires the HTTP site (routes, views, and embedded assets).
site/books
Package books wires the "books" site feature.
Package books wires the "books" site feature.
site/books/controller
Package controller defines MVC controllers for the books feature.
Package controller defines MVC controllers for the books feature.
site/books/model
Package model defines the data structures used by the books feature.
Package model defines the data structures used by the books feature.
site/books/repository
Package repository provides access to the books data used by the site.
Package repository provides access to the books data used by the site.
site/books/route
Package route registers HTTP routes for the books feature.
Package route registers HTTP routes for the books feature.
site/books/view
Package view provides view constructors for the books feature.
Package view provides view constructors for the books feature.
site/errors
Package errors wires the site's error feature.
Package errors wires the site's error feature.
site/errors/controller
Package controller defines MVC controllers for the error feature.
Package controller defines MVC controllers for the error feature.
site/errors/model
Package model defines view models for the error feature.
Package model defines view models for the error feature.
site/errors/route
Package route registers the global not-found handler for the error feature.
Package route registers the global not-found handler for the error feature.
site/errors/view
Package view defines MVC views for the error feature.
Package view defines MVC views for the error feature.
site/favicon
Package favicon registers the site's browser icon endpoint.
Package favicon registers the site's browser icon endpoint.
site/meta
Package meta provides shared, cross-cutting metadata used by site view models.
Package meta provides shared, cross-cutting metadata used by site view models.
site/robots
Package robots registers the robots.txt endpoint for the site.
Package robots registers the robots.txt endpoint for the site.
site/root
Package root wires the site's root (home) feature.
Package root wires the site's root (home) feature.
site/root/controller
Package controller defines MVC controllers for the root (home) feature.
Package controller defines MVC controllers for the root (home) feature.
site/root/model
Package model defines the data structures used by the root (home) feature.
Package model defines the data structures used by the root (home) feature.
site/root/route
Package route registers HTTP routes for the root (home) feature.
Package route registers HTTP routes for the root (home) feature.
site/root/view
Package view provides view constructors for the root (home) feature.
Package view provides view constructors for the root (home) feature.
site/security
Package security provides browser security headers for the site.
Package security provides browser security headers for the site.
site/sitemap
Package sitemap registers the site's sitemap.xml endpoint.
Package sitemap registers the site's sitemap.xml endpoint.
site/static
Package static registers embedded static assets with the site's public, one-hour cache policy.
Package static registers embedded static assets with the site's public, one-hour cache policy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL