apprun

package
v0.0.0-...-54c120a Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package apprun represents a simple application runner with application dependencies

Index

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

func WithDepProvider[D io.Closer](dp func() (D, error)) func(a *AppRunner[D])

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

func WithDepProviderCtx

func WithDepProviderCtx[D io.Closer](
	dp func(ctx context.Context) (D, error),
) func(a *AppRunner[D])

WithDepProviderCtx set the dependency provider func for the App Runner with context for more info see WithDepProvider

func WithForceTracingEnabled

func WithForceTracingEnabled[D io.Closer](isEnabled bool) func(a *AppRunner[D])

WithForceTracingEnabled force tracing enabled/disabled It overrides default behavior, where whether tracing is enabled is based on TRACING_ENABLED env var

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

func NewAppRunner[D io.Closer](ops ...func(a *AppRunner[D])) AppRunner[D]

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

func (a *AppRunner[D]) Run(
	ctx context.Context,
	body func(ctx context.Context, d D) error,
) error

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

func (EmptyDeps) Close

func (e EmptyDeps) Close() error

Close 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

Jump to

Keyboard shortcuts

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