{"id":51552911,"url":"https://github.com/rluders/lane","last_synced_at":"2026-07-10T01:03:26.753Z","repository":{"id":363456284,"uuid":"1263428555","full_name":"rluders/lane","owner":"rluders","description":"Lane manages startup, health checks, and graceful shutdown for HTTP servers, workers, schedulers, and other service components under a unified lifecycle.","archived":false,"fork":false,"pushed_at":"2026-06-09T00:59:06.000Z","size":2062,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-09T02:26:18.228Z","etag":null,"topics":["golang","golang-library","graceful-shutdown","runtime","scheduler","timeout-control"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rluders.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-09T00:24:05.000Z","updated_at":"2026-06-09T01:04:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rluders/lane","commit_stats":null,"previous_names":["rluders/lane"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/rluders/lane","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluders%2Flane","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluders%2Flane/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluders%2Flane/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluders%2Flane/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rluders","download_url":"https://codeload.github.com/rluders/lane/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rluders%2Flane/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35316840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-09T02:00:07.329Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","golang-library","graceful-shutdown","runtime","scheduler","timeout-control"],"created_at":"2026-07-10T01:03:25.996Z","updated_at":"2026-07-10T01:03:26.747Z","avatar_url":"https://github.com/rluders.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./.github/logo.png\" alt=\"Lane\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/rluders/lane/actions/workflows/ci.yml\"\u003e\n    \u003cimg src=\"https://github.com/rluders/lane/actions/workflows/ci.yml/badge.svg\" alt=\"CI\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://go.dev/doc/devel/release\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/go-1.26+-00ADD8?logo=go\u0026logoColor=white\" alt=\"Go 1.26+\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pkg.go.dev/github.com/rluders/lane\"\u003e\n    \u003cimg src=\"https://pkg.go.dev/badge/github.com/rluders/lane.svg\" alt=\"Go Reference\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://goreportcard.com/report/github.com/rluders/lane\"\u003e\n    \u003cimg src=\"https://goreportcard.com/badge/github.com/rluders/lane\" alt=\"Go Report Card\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/rluders/lane/releases\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/v/release/rluders/lane?sort=semver\" alt=\"GitHub release\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/rluders/lane\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/rluders/lane/branch/main/graph/badge.svg\" alt=\"codecov\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/rluders/lane\" alt=\"License\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/dependencies-1-blue\" alt=\"1 dependency\"\u003e\n\u003c/p\u003e\n\n## 🤔 What is lane?\n\n`lane` manages the startup, health, and graceful shutdown of one or more service components — HTTP servers, background workers, schedulers — under a unified context. Register your runners, call `Run`, and lane handles the rest.\n\n## 🎯 Why use it?\n\nWiring SIGINT/SIGTERM handling, concurrent startup, health probes, and ordered shutdown correctly is tedious boilerplate. `lane` does it once, predictably, so services stay focused on their own logic.\n\n## 🚫 What it does NOT do\n\n- It is not a dependency injection framework\n- It does not wire, store, or own your service dependencies\n- It does not prescribe configuration, logging format, or database access patterns\n- It does not define application structure beyond the `Runner` interface\n\nDependency wiring is the caller's responsibility.\n\n## ⚡ Quick Example\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log/slog\"\n    \"net/http\"\n    \"os\"\n    \"time\"\n\n    \"github.com/rluders/lane\"\n    \"github.com/rluders/lane/runners\"\n)\n\nfunc main() {\n    lane.RunHealthCheck(\":8080\")\n\n    log := slog.New(slog.NewTextHandler(os.Stderr, nil))\n\n    mux := http.NewServeMux()\n\n    l := lane.New(log, lane.WithShutdownTimeout(10*time.Second))\n\n    mux.Handle(\"GET /ready\", lane.ReadinessHandler(l.Health()))\n    mux.Handle(\"GET /live\", lane.LivenessHandler())\n\n    server := \u0026http.Server{Addr: \":8080\", Handler: mux}\n    l.AddRunner(runners.NewHTTPRunner(\"api\", server, log))\n\n    if err := l.Run(context.Background()); err != nil {\n        log.Error(\"lane error\", \"error\", err)\n        os.Exit(1)\n    }\n}\n```\n\n## 🔄 Lifecycle\n\n```mermaid\nflowchart TD\n    A[lane.New] --\u003e B[AddRunner x N]\n    B --\u003e C[l.Run]\n    C --\u003e D[Start all runners concurrently]\n    D --\u003e E[health.SetReady true]\n    E --\u003e F{waiting}\n    F -- SIGINT/SIGTERM --\u003e G[Signal received]\n    F -- runner error --\u003e H[Context cancelled]\n    G --\u003e I[health.SetReady false]\n    H --\u003e I\n    I --\u003e J[Stop runners in LIFO order]\n    J --\u003e K[Shutdown timeout context]\n    K --\u003e L[Return first error or nil]\n```\n\nRunners are started concurrently. Shutdown is sequential in **reverse registration order** (LIFO), so dependents stop before the services they depend on.\n\n## 🧩 Runner Interface\n\nAny component that can start and stop is a Runner:\n\n```go\ntype Runner interface {\n    Name() string\n    Start(ctx context.Context) error\n    Stop(ctx context.Context) error\n}\n```\n\n**Contract:**\n- `Start` **must block** until the runner stops or fails\n- `Stop` initiates graceful shutdown and **must respect the context deadline**\n- If `Start` returns a non-nil error, lane cancels all other runners\n\n## 📦 Built-in Runners\n\nAll implementations live in the `runners/` sub-package.\n\n| Runner | Constructor | Description |\n|--------|-------------|-------------|\n| HTTP | `runners.NewHTTPRunner(name, server, log)` | Wraps `*http.Server`. Calls `Shutdown` on stop. |\n| HTTPS | `runners.NewHTTPSRunner(name, server, certFile, keyFile, log)` | Same as HTTPRunner with TLS. |\n| Worker | `runners.NewWorkerRunner(name, fn, log)` | Runs a `WorkFn` in a loop until ctx is cancelled. |\n| Scheduler | `runners.NewSchedulerRunner(name, interval, fn, log)` | Runs a `JobFn` on a fixed interval. Missed ticks are dropped. |\n\n### Worker example\n\n```go\nworker := runners.NewWorkerRunner(\"processor\", func(ctx context.Context) error {\n    return processNextMessage(ctx)\n}, log)\nl.AddRunner(worker)\n```\n\n### Scheduler example\n\n```go\nsched := runners.NewSchedulerRunner(\"cleanup\", 5*time.Minute, func(ctx context.Context) error {\n    return purgeExpiredSessions(ctx)\n}, log)\nl.AddRunner(sched)\n```\n\n## 🏥 Health Checks\n\n`HealthState` tracks readiness. Lane sets it to ready after all runners start, and back to not-ready at the beginning of shutdown.\n\n```go\nmux.Handle(\"GET /ready\", lane.ReadinessHandler(l.Health(), db.PingContext))\nmux.Handle(\"GET /live\", lane.LivenessHandler())\n```\n\n`ReadinessHandler` accepts zero or more probe functions of type `func(ctx context.Context) error`. All probes must pass for the endpoint to return 200. If any probe fails, the endpoint returns 503.\n\n`LivenessHandler` always returns 200 — a running process is a live process.\n\n### Container health probe\n\nCall `RunHealthCheck` at the very top of `main()` to support Docker `HEALTHCHECK CMD`-based probes:\n\n```go\nfunc main() {\n    lane.RunHealthCheck(\":8080\")\n    // ... rest of main\n}\n```\n\nWhen invoked as `myservice healthcheck`, the process exits 0 (healthy) or 1 (unhealthy) immediately without starting the service.\n\n## 🛡️ Recovery\n\n### Goroutine recovery\n\n`lane.Go` runs a goroutine with structured panic recovery. On panic it logs the stack trace and calls the provided cancel function to propagate the failure up to lane.\n\n```go\nlane.Go(ctx, log, \"worker-name\", cancel, func(ctx context.Context) {\n    // critical goroutine — a panic here cancels the application context\n})\n```\n\n### HTTP handler recovery\n\n`RecoverMiddleware` wraps HTTP handlers with panic recovery. On panic it logs structured context (method, path, stack trace) and returns HTTP 500. The service continues — a single handler panic is recoverable.\n\n```go\nhandler = lane.RecoverMiddleware(log)(handler)\n```\n\n## ⏱️ Shutdown Timeout\n\nDefault shutdown timeout is **30 seconds**. Override with `WithShutdownTimeout`:\n\n```go\nl := lane.New(log, lane.WithShutdownTimeout(10*time.Second))\n```\n\nEach runner's `Stop` is called with a context that respects this deadline. If a runner does not stop within the timeout, shutdown proceeds without it.\n\n## 🗓️ When to use lane\n\nUse it when you want:\n\n- ✅ Go services with multiple concurrent components (API server + worker + scheduler)\n- ✅ Predictable SIGTERM handling and readiness probes in containers\n- ✅ Correct lifecycle management without pulling in a full service framework\n\nAvoid it if you need:\n\n- ❌ A dependency injection container\n- ❌ A full application framework with routing conventions\n- ❌ Managed configuration, observability, or deployment tooling\n\n## 📄 License\n\nMIT — see [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frluders%2Flane","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frluders%2Flane","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frluders%2Flane/lists"}