deferred-init

command
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 8 Imported by: 0

README

Deferred initialization

This example keeps liveness separate from traffic readiness while a slow startup task runs. The process is alive immediately, but application traffic does not become ready until WithDeferredInit and every WithOnReady hook succeeds.

Run

go run ./examples/deferred-init

From another terminal while it starts:

curl -i http://localhost:9080/healthz/     # 200 immediately
curl -i http://localhost:9080/readyz/      # 503, then 200 after about 3 seconds
curl -i http://localhost:8080/api/users    # 503, then the JSON response

The separate :9080 listener is the stable probe surface. Liveness answers whether the process should be restarted; readiness answers whether it should receive traffic. The /api/users route is registered by an OnReady hook to show that route setup can depend on successful initialization.

Documentation

Overview

Deferred-init example.

Demonstrates keeping the health listener live while long-running bootstrap work runs in the background. Application routes return 503 until bootstrap and the OnReady hook both succeed, then the server flips to ready.

Run it:

go run ./examples/deferred-init

Then in another shell:

curl -i http://localhost:9080/healthz/   # 200 immediately
curl -i http://localhost:9080/readyz/    # 503, then 200
curl -i http://localhost:8080/api/users  # 503 until ready (~3s), then 200

Jump to

Keyboard shortcuts

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