Skip to main content

Reference

The exact names and signatures, in one place. The other pages explain when to use them.

Framework environment variables​

These belong to the framework. Your services define their own variables in their Config structs.

VariableMeaningDefault
LOG_LEVELdebug, info, warn, or error logging threshold.info
LOG_FORMATjson or text output.text
LOG_ADD_SOURCEInclude the source location in log records.false
ENVRead by goenv. Only dev is recognized; any other value, or none, means prod. The framework logs it at startup and does not change behavior on it.prod
RUNNER_SHUTDOWNTIMEOUTDeadline for the whole graceful shutdown, as a Go duration.10s
SERVICES_ENABLEDComma-separated list of the services to run in this process, by ServiceName. Empty or unset runs every registered service.all
SERVICES_ENABLED=price-worker,api LOG_LEVEL=debug ./build/my-service run

Service interfaces​

Defined in internal/pkg/service-manager/service_manager.go. Every service implements Service. The others are optional, and one service can implement any combination of them.

type Service interface {
Name() string
Run(ctx context.Context) error
Stop(ctx context.Context) error
}

// Retry a failed Run up to MaxRetries() times, RetryDelay() apart.
// A negative MaxRetries counts as 0.
type Retryable interface {
MaxRetries() int
RetryDelay() time.Duration
}

// Return true to keep the application running after this service
// fails for good.
type AllowedFailure interface {
IsAllowedFailure() bool
}

// Start after the named services.
type Dependent interface {
Dependencies() []string
}

// Close the channel once the service can serve. Later dependency
// groups wait for it.
type ReadyNotifier interface {
Ready() <-chan struct{}
}

// Add subcommands under ./build/<app> <service> <subcommand>.
type Commander interface {
Commands() []*cobra.Command
}

Services and lifecycle explains how the manager applies each one.

Service package rules​

make service-registration scans internal/pkg/services/ for types that implement Service and writes internal/pkg/services/services.gen.go. For each implementation, its package must export:

  • const ServiceName, the name used to register the service, to select it in SERVICES_ENABLED, and as its command namespace;
  • func New() (*T, error), where *T is the type that implements Service.

make service writes both. If you write a service by hand, add them, or the generated file does not compile. Keep one Service implementation per package.

Return ServiceName from Name(). The manager uses Name() to resolve Dependencies() and to name the service in logs, so a different value makes dependency declarations and SERVICES_ENABLED refer to different names.

Packages can be nested, for example internal/pkg/services/http/api. make service does not accept a / in NAME, so create nested packages by hand and run make service-registration. The generator builds each import alias from the path under services/ with / and - removed (http/api becomes httpapi), so packages with the same name in different directories do not collide. With no services at all, the generated Init panics with No services.

Make targets​

Run make help for the list your copy has. servicepack-reformat also appears there; the update uses it internally. The Script column names the script a target runs. Copy that script from scripts/make/servicepack/ to scripts/make/ to override it (see development). Targets without a script are defined directly in Makefile.servicepack; override those by defining the target in your Makefile.

TargetScriptWhat it does
make own MODNAME=<module>own.shTurn a fresh clone into your project. Run it once.
make service NAME=<name>service.shCreate a service and regenerate registration.
make service-remove NAME=<name>service_remove.shDelete a service and regenerate registration.
make service-registrationservice_registration.shRegenerate services.gen.go.
make buildbuild.shBuild the static binary into build/<app>.
make run-devrun_dev.shBuild the development image and run the app in it with the race detector.
make docker-builddocker_build.shBuild the production image.
make dev-image, make docker-build-devdocker_build_dev.shBuild the development image the other targets run in.
make shellOpen a shell in the development image.
make testtest.shRace-enabled go test ./... with the Docker socket.
make test-unitRace-enabled go test ./... without the Docker socket.
make test-integrationUncached race-enabled go test -tags=integration ./... with the Docker socket and a ten-minute timeout.
make test-coveragetest_coverage.shCoverage run with -tags=integration; fails under MIN_TEST_COVERAGE (default 90).
make lintlint.shshfmt, ShellCheck, a go fix diff check and golangci-lint.
make lint-fixlint_fix.shApply the supported fixes. Review the diff.
make formatgofumpt and shfmt.
make secsec.shgovulncheck and semgrep, merged into sec.sarif. Fails on any finding. Needs network access for the semgrep rules.
make generatego generate ./....
make cleanclean.shRemove build output and coverage files.
make alldep, lint-fix, test-coverage, then build.
make dep, make pkg-lockgo mod tidy and go mod vendor without changing versions.
make pkg-add PKG=<module>@<version>Add a module.
make pkg-update PKG=<module>Update one module to its latest version.
make pkg-upgradeUpgrade every direct module to its latest version.
make pkg-remove PKG=<module>Remove a module.
make pkg-add-tool MODULE=<module>@<version> TOOL=<package>Add a Go tool directive.
make pkg-remove-tool TOOL=<package>Remove a Go tool directive.
make servicepack-updateservicepack_update.shBring in the latest framework on a review branch.
make servicepack-update-reviewservicepack_update_review.shShow the pending update.
make servicepack-update-mergeservicepack_update_merge.shMerge the pending update.
make servicepack-update-revertservicepack_update_revert.shDrop the pending update.
make backupbackup.shArchive the project before risky work.
make backup-restore [BACKUP=<file>]backup_restore.shRestore a backup, the latest by default.
make backup-clearbackup_clear.shDelete every backup.

Module age gate​

pkg-add, pkg-update, pkg-upgrade and pkg-add-tool refuse a module version published less than seven days ago. Modules under github.com/psyb0t/ are exempt.

pkg-update and pkg-upgrade check the latest version and stop when it is too new; they do not fall back to an older one. pkg-upgrade checks every direct module before it changes any, so one refusal leaves go.mod and vendor/ as they were. The check is scripts/check-go-age.sh.