Documentation ΒΆ
Overview ΒΆ
Package nilgo provides a simple way to bootstrap an production-ready application.
Index ΒΆ
- type Option
- func WithLogger(logger *slog.Logger) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithPostRun(runs ...func(context.Context) error) Option
- func WithPreRun(runs ...func(context.Context) error) Option
- func WithStartGate(gates ...func(context.Context) error) Option
- func WithStopGate(gates ...func(context.Context) error) Option
- func WithTraceProvider(provider trace.TracerProvider) Option
- type Runner
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Option ΒΆ added in v0.2.0
type Option func(*options)
Option configures the Runner with specific options.
func WithLogger ΒΆ added in v0.2.0
WithLogger provides a slog.Logger to handle logs.
func WithMeterProvider ΒΆ added in v0.2.0
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider provides OpenTelemetry metric provider.
func WithPostRun ΒΆ added in v0.2.0
WithPostRun provides runs to execute after the main runs provided in Runner.Run.
func WithPreRun ΒΆ added in v0.2.0
WithPreRun provides runs to execute before the main runs provided in Runner.Run.
It's guaranteed that all goroutines for pre-runs start before the main runs start, and end after the main runs end if it's blocking with context.Context.Done.
func WithStartGate ΒΆ added in v0.2.0
WithStartGate provides gates to block the start of main runs provided in Runner.Run, until all start gates returns without error.
All start gates must return in limited time to avoid blocking the main runs.
func WithStopGate ΒΆ added in v0.2.0
WithStopGate provides gates to block the stop of main runs provided in Runner.Run, until all stop gates returns.
All stop gates must return in limited time to avoid blocking the main runs.
func WithTraceProvider ΒΆ added in v0.2.0
func WithTraceProvider(provider trace.TracerProvider) Option
WithTraceProvider provides OpenTelemetry trace provider.
type Runner ΒΆ added in v0.2.0
type Runner struct {
// contains filtered or unexported fields
}
Runner is a pre-configured runtime for executing runs in parallel.
To create an Runner, use New.
func (Runner) Run ΒΆ added in v0.2.0
Run executes the given run in parallel with well-configured runtime, which includes logging, configuration, and telemetry.
The run running in parallel without any explicit order, which means it should not have temporal dependencies between each other.
The execution can be interrupted if any run returns non-nil error, or it receives an OS signal syscall.SIGINT or syscall.SIGTERM. It waits all run return unless it's forcefully terminated by OS.
The execution flow is as follows: 1. Starts all pre runs and start gates in parallel. 2. Waits for all pre runs start and start gates complete. 3. Starts all main runs. 4. Waits for OS interrupt or terminal signals or all main runs complete. 5. Waits for all stop gates complete. 6. Stop all main runs. 7. Waits for all post runs complete.