web

command module
v1.263.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 3 Imported by: 0

README

CircleCI codecov Go Report Card 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 templates and content 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)
  • exposes health and liveness/readiness endpoints (see below)

The HTML templates and the books YAML data are embedded into the binary using go:embed.

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-service/v2/di. 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/v2/net/http/mvc

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

Embedded assets

The site package embeds:

  • templates for layout and pages
  • the books YAML file used to render the books page

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

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.

Health

The service registers health checks and exposes standard probe endpoints:

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

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

Development

Prerequisites

Install:

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 Go tests
go test ./...

# Run Ruby specs / acceptance tests (if you are working on the test harness)
make specs
make features
Running locally

There are two common ways to run the service:

1) Dev mode

Use the dev target (recommended while iterating):

make dev

This typically runs the service with a development configuration (see the Makefile includes and CI configuration for how it is invoked).

2) Build and run the binary

Build a local binary:

make build

Then run it:

./tmp/web server

The CLI command is server. It is 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.

Pages:

curl -i http://localhost:8080/
curl -i http://localhost:8080/books
curl -i http://localhost:8080/robots.txt

Partial renders (PUT):

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

Health:

curl -i http://localhost:8080/healthz
curl -i http://localhost:8080/livez
curl -i http://localhost:8080/readyz

Ports, TLS, and other server settings are controlled by configuration. If your local environment differs, inspect the config used by make dev / CI.

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 health section looks conceptually like:

health:
  duration: 5s
  timeout: 2s

The exact full configuration file shape depends on the embedded go-service base config and the environment in which you run the binary. For canonical examples, check the CI configuration and any config files used by make dev.

Testing

Go

Run all Go tests:

go test ./...
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 / releases

See:

  • CHANGELOG.md

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/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.

Jump to

Keyboard shortcuts

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