Skip to content

Releases: struct0x/exitplan

v1.0.0

27 Jan 16:18
v1.0.0
12e44a5

Choose a tag to compare

The first stable release of Exitplan - a Go library for managing application lifecycle with graceful shutdown.

Features

  • Simple two-phase lifecycle - Running and Teardown phases with clear context boundaries
  • Graceful shutdown - Register cleanup callbacks executed in LIFO order (last registered, first executed)
  • Signal handling - Built-in support for OS signals (SIGINT, SIGTERM, etc.)
  • Flexible callbacks - Four variants to match your needs:
    • OnExit() - simple cleanup
    • OnExitWithError() - cleanup with error handling
    • OnExitWithContext() - context-aware cleanup
    • OnExitWithContextError() - full control
  • Callback options - Async, Timeout(), Name(), PanicOnError
  • Automatic callback identification - Callbacks are named by their source location (file:line) by default
  • Structured error reporting - CallbackErr wraps errors with callback names for debugging
  • Startup timeout - Detect stuck initialization with WithStartupTimeout()
  • Readiness signaling - Started() channel for health probes and service coordination

API

package main

import (
	"github.com/struct0x/exitplan"
)

func main() {
	ex := exitplan.New(
		exitplan.WithSignal(syscall.SIGINT, syscall.SIGTERM),
		exitplan.WithTeardownTimeout(30*time.Second),
	)

	ex.OnExit(func() {
		// cleanup
	})

	go worker(ex.Context())

	go func() {
		<-ex.Started() // ready for traffic
	}()

	ex.Run() // blocks until shutdown
}

Contexts

Method Purpose
Started() Channel closed when Run() is called
Context() App lifetime, canceled on shutdown
TeardownContext() Cleanup phase, canceled on timeout

Installation

go get github.com/struct0x/exitplan@v1.0.0

Links