# README
Bootstrap
A Go package for managing service lifecycle with graceful startup and shutdown capabilities.
Features
-
Flexible Service Management:
- Ordered service startup and shutdown
- Parallel service startup for unordered services
- After-start services that run after main services
- Graceful shutdown handling
-
Health Checks:
- Readiness checks for service availability
- Liveness checks for service health
- Custom error handling for failed health checks
-
Resilient Operations:
- Configurable restart policies using backoff strategies
- Graceful shutdown with configurable timeouts
- Context-based cancellation support
-
Extensible Logging:
- Context-aware logging methods
- Flexible logger implementation
Installation
go get github.com/n-r-w/bootstrap
Usage
See example
Configuration Options
WithStartTimeout(timeout time.Duration)
: Sets the timeout for service startupWithStopTimeout(timeout time.Duration)
: Sets the timeout for graceful shutdownWithHealthCheck(checker IHealthChecker)
: Configures health checkingWithOrdered(services ...IService)
: Adds services that must start in orderWithUnordered(services ...IService)
: Adds services that can start in parallelWithAfterStart(services ...IService)
: Adds services to start after all othersWithRunFunc(func(context.Context) error)
: Sets a function to run after services startWithLogger(logger ILogger)
: Configures a custom logger
Service Interface
Services must implement the IService
interface:
type IService interface {
Info() Info
Start(ctx context.Context) error
Stop(ctx context.Context) error
}
The Info
struct contains:
Name
: Service identifierRestartPolicy
: Optional backoff configuration for restart attempts
Health Checks
Health checks can be added using the IHealthChecker
interface
Executor package
Executor package provides an interface for executing a function at specified time intervals. Supports bootstrap.IService interface.