bootstrap

package
v1.100.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

Package bootstrap provides a simple way to bootstrap an application with managed configuration, logging, metrics, application context, and shutdown signals.

For an implementation example see in order:

  • examples/service/cmd/main.go
  • examples/service/internal/cli/cli.go
  • examples/service/internal/cli/bind.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(bindFn BindFunc, opts ...Option) error

Bootstrap is the function in charge of configuring the core components of an application and handling the lifecycle of its context.

Types

type BindFunc

type BindFunc func(context.Context, *zap.Logger, metrics.Client) error

BindFunc represents the function responsible to wire up all components of the application.

type CreateLoggerFunc

type CreateLoggerFunc func() (*zap.Logger, error)

CreateLoggerFunc creates a new logger.

type CreateMetricsClientFunc

type CreateMetricsClientFunc func() (metrics.Client, error)

CreateMetricsClientFunc creates a new metrics client.

type Option

type Option func(*config)

Option is a type alias for a function that configures the application logger.

func WithContext

func WithContext(ctx context.Context) Option

WithContext overrides the application context (useful for testing).

func WithCreateLoggerFunc

func WithCreateLoggerFunc(fn CreateLoggerFunc) Option

WithCreateLoggerFunc overrides the root logger creation function.

func WithCreateMetricsClientFunc

func WithCreateMetricsClientFunc(fn CreateMetricsClientFunc) Option

WithCreateMetricsClientFunc overrides the default metrics client register.

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger overrides the default application logger.

func WithShutdownSignalChan added in v1.73.0

func WithShutdownSignalChan(ch chan struct{}) Option

WithShutdownSignalChan sets the shared channel uset to signal a shutdown. The channel is set when the shutdown process starts. Dependants (e.g. HTTP servers) should read this channel and start their shutdown process.

func WithShutdownTimeout added in v1.72.0

func WithShutdownTimeout(timeout time.Duration) Option

WithShutdownTimeout sets the shutdown timeout. This is the time to wait on exit for a graceful shutdown.

func WithShutdownWaitGroup added in v1.72.0

func WithShutdownWaitGroup(wg *sync.WaitGroup) Option

WithShutdownWaitGroup sets the shared waiting group to communicate externally when the server is shutdown. On shutdown Bootstrap will wait for the wg to be zero or the shutdownTimeout to be reached before returning. Dependants (e.g. HTTP servers) should increment this group when they start, and reset it when their shutdown process is completed.

Jump to

Keyboard shortcuts

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