Documentation ¶
Overview ¶
Package apprun represents a simple application runner with application dependencies
Index ¶
- func Start(appCtx context.Context, params StartParams) (chan error, error)
- func WithDepProvider[D io.Closer](dp func() (D, error)) func(a *AppRunner[D])
- func WithDepProviderCtx[D io.Closer](dp func(ctx context.Context) (D, error)) func(a *AppRunner[D])
- func WithForceTracingEnabled[D io.Closer](isEnabled bool) func(a *AppRunner[D])
- type AppRunner
- type EmptyDeps
- type StartParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Start ¶
func Start(appCtx context.Context, params StartParams) (chan error, error)
Start executing the StartParams.Start function asynchronously and then clean up/shutdown the execution
func WithDepProvider ¶
WithDepProvider set the dependency provider func for the App Runner Dependency provided, provides dependencies for the application dependencies are for example database connection pools, redis, mongo clients ... The dependencies are then injected to the function body provided to the Run method
Types ¶
type AppRunner ¶
type AppRunner[D io.Closer] struct { DependencyProvider func(ctx context.Context) (D, error) // contains filtered or unexported fields }
AppRunner represents a runner for the application generic parameter D (as dependencies) must implement closer, the Run method closes the "dependencies" after the execution
func NewAppRunner ¶
NewAppRunner create a new application runner instance Datadog Tracing can be enabled/disabled in 2 ways, you can either: - set TRACING_ENABLED env variable to true/false - directly call WithForceTracingEnabled(true/false) function WithForceTracingEnabled - has precedence and overrides env variable it can be useful for testing
func (*AppRunner[D]) Run ¶
Run the application The method will: - enable/disable datadog tracing - creates dependencies using the DependencyProvider callback - handles the application shutdown - (app receives the signal) - provides the initialized dependencies and context to the function body callback - do cleanup - closes dependencies, stops the application
type EmptyDeps ¶
type EmptyDeps struct{}
EmptyDeps represents an empty dependency instance
func NewEmptyDeps ¶
func NewEmptyDeps() *EmptyDeps
NewEmptyDeps return a new instance of the empty dependencies
type StartParams ¶
type StartParams struct { Start func(ctx context.Context) error Stop func(ctx context.Context) error GraceTimeout time.Duration }
StartParams parameters for the Start function; Start defines the start callback - function that will be executed async way Stop defines a stop/shutdown callback - function that will executed to cleanup/stop the Start function