lifecycle

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App interface {
	// Main is the primary application logic function to be executed.
	// ctx is the main context for all application logic
	// loggingCtx is a longer-lived context for background logging routines that is canceled after cleanup
	Main(ctx context.Context, loggingCtx context.Context) error
}

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(impl App) *Application

NewApplication creates a new Application with specified implementation

There are two contexts available:

  • ctx: main context, all application actions should use this, canceled before cleanup
  • loggingCtx: lives slightly longer than the main context, canceled after cleanup, dedicated for logging background routines that need to run during cleanup

func (*Application) Context

func (app *Application) Context() context.Context

Context returns the application's main context. This context is used as the primary driver for the application's operations.

func (*Application) LoggingContext

func (app *Application) LoggingContext() context.Context

LoggingContext returns the application's dedicated logging context. In contrast to the main context, it stays active during cleanup to allow background logs to be delivered

func (*Application) Run

func (app *Application) Run() error

Run executes the application's main function within the configured contexts. Returns an error if the application has already been canceled or an eventual error from main

type CancellableContext

type CancellableContext struct {
	// contains filtered or unexported fields
}

func DeriveContext

func DeriveContext(parent context.Context) *CancellableContext

DeriveContext creates a new cancellable Context derived from the provided parent context.

func (*CancellableContext) Cancel

func (c *CancellableContext) Cancel()

func (*CancellableContext) Deadline

func (c *CancellableContext) Deadline() (deadline time.Time, ok bool)

func (*CancellableContext) Done

func (c *CancellableContext) Done() <-chan struct{}

func (*CancellableContext) Err

func (c *CancellableContext) Err() error

func (*CancellableContext) Value

func (c *CancellableContext) Value(key any) any

type CleanableApp

type CleanableApp interface {
	// Cleanup is a function to handle cleanup tasks when the application stops.
	// ctx is the main context for all application logic
	// loggingCtx is a longer-lived context for background logging routines that is canceled after cleanup
	Cleanup(ctx context.Context, loggingCtx context.Context)
}

type ImmediateExitApp

type ImmediateExitApp interface {
	// ImmediateExit is invoked on receiving a second termination signal during shutdown.
	ImmediateExit()
}

Jump to

Keyboard shortcuts

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