application

package module
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: BSD-3-Clause Imports: 3 Imported by: 3

README

application

Go Reference Maintainability Rating Quality Gate Status

Package application offers simple application lifecycle framework.

Running the application lifecycle

You can use Run or RunAll functions to enter the application lifecycle. Please read go reference.

Building with version

You can save your application's name, version and build into this package below this.

go build -ldflags "\
-X=github.com/goinsane/application.name=$NAME \
-X=github.com/goinsane/application.version=$VERSION \
-X=github.com/goinsane/application.build=$BUILD \
" ./...

Documentation

Overview

Package application offers simple application lifecycle framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build() string

Build returns application.build defined with ldflags.

func Name added in v0.1.1

func Name() string

Name returns application.name defined with ldflags.

func Run

func Run(ctx context.Context, app Application, terminateTimeout, quitTimeout time.Duration) bool

Run runs an instance of Application by the application lifecycle with the given ctx and timeouts. It returns false if the quit timeout occurs. Quit timeout has to be greater than terminate timeout. And it starts after the application context was canceled.

func RunAll added in v1.1.0

func RunAll(ctx context.Context, apps []Application, terminateTimeout, quitTimeout time.Duration) bool

RunAll runs all instances of Application in common context.Context by the application lifecycle with the given ctx and timeouts. It returns false if the quit timeout occurs. Quit timeout has to be greater than terminate timeout. And it starts after the application context was canceled.

func Version

func Version() string

Version returns application.version defined with ldflags.

Types

type Application

type Application interface {
	// Start is always called when the lifecycle starts.
	// ctx is the application context and can be canceled by the cancel function.
	Start(ctx context.Context, cancel context.CancelFunc)
	// Run is called after the Start method if the application context has not been canceled.
	// ctx is the application context and can be canceled by the cancel function.
	Run(ctx context.Context, cancel context.CancelFunc)
	// Terminate is called after the application context was cancelled, with the terminate context which has the given terminate timeout.
	// If the application context is canceled before the Run method, Terminate is not called.
	// ctx is the terminate context.
	Terminate(ctx context.Context)
	// Stop is always called when the lifecycle ends even the Run method was not called.
	Stop()
}

Application is an interface for handling the application lifecycle. Run and RunAll functions trigger the application lifecycle, and enter methods of the Application interface with the given order.

type Instance added in v1.4.1

type Instance struct {
	StartFunc     func(ctx context.Context, cancel context.CancelFunc)
	RunFunc       func(ctx context.Context, cancel context.CancelFunc)
	TerminateFunc func(ctx context.Context)
	StopFunc      func()
}

Instance is a method wrapper to implement Application interface.

func (*Instance) Run added in v1.4.1

func (a *Instance) Run(ctx context.Context, cancel context.CancelFunc)

func (*Instance) Start added in v1.4.1

func (a *Instance) Start(ctx context.Context, cancel context.CancelFunc)

func (*Instance) Stop added in v1.4.1

func (a *Instance) Stop()

func (*Instance) Terminate added in v1.4.1

func (a *Instance) Terminate(ctx context.Context)

Jump to

Keyboard shortcuts

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