application

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Application is a collection of microservices that run in a single process and share the same lifecycle

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

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

Application is a collection of microservices that run in a single process and share the same lifecycle.

func New

func New() *Application

New creates a new application. An application is a collection of microservices that run in a single process and share the same lifecycle. A unique plane of communication is used to isolate the app if it is running in a unit test environment.

func (*Application) Add

func (app *Application) Add(services ...service.Service)

Add adds a collection of microservices to be managed by the app. Added microservices are not started up immediately. An explicit call to [Startup] or [Run] is required. Microservices that are added together are started in parallel. Otherwise, microservices are started sequentially in order of inclusion.

In the following example, A is started first, then B1 and B2 in parallel, and finally C1 and C2 in parallel.

app := application.New()
app.Add(a)
app.Add(b1, b2)
app.Add(c1, c2)
app.Run()

func (*Application) AddAndStartup

func (app *Application) AddAndStartup(ctx context.Context, services ...service.Service) (err error)

AddAndStartup adds a collection of microservices to the app, and starts them up immediately.

func (*Application) Interrupt

func (app *Application) Interrupt()

Interrupt the app.

func (*Application) Remove

func (app *Application) Remove(services ...service.Service)

Remove removes the microservices from under management of the app. Removed microservices are not shut down automatically and remain running on the same plane of communications.

func (*Application) Run

func (app *Application) Run() error

Run starts up all microservices included in this app, waits for interrupt, then shuts them down. Microservices are give 20 seconds to start and shutdown. For finer timeout control, use [Startup] and [Shutdown].

func (*Application) RunInTest added in v1.17.0

func (app *Application) RunInTest(t testing.TB) error

RunInTest starts up all microservices included in this app, waits for the test to finish, then shuts them down. A random plane of communication is used to isolate the testing app from other apps. Errors in startup or shutdown will fail the test.

func (*Application) Shutdown

func (app *Application) Shutdown(ctx context.Context) error

Shutdown shuts down all started microservices included in this app in the reverse order of their starting up. If an error is returned, there is no guarantee as to the state of the microservices: some microservices may have been shut down while others not. The context deadline is used to limit the time allotted to the operation.

func (*Application) Startup

func (app *Application) Startup(ctx context.Context) error

Startup starts all unstarted microservices included in this app. Microservices that are included together are started in parallel together. Otherwise, microservices are started sequentially in order of inclusion. If an error is returned, there is no guarantee as to the state of the microservices: some microservices may have been started while others not. The context deadline is used to limit the time allotted to the operation.

func (*Application) WaitForInterrupt

func (app *Application) WaitForInterrupt()

WaitForInterrupt blocks until an interrupt is received through a SIGTERM, SIGINT or a call to interrupt.

Jump to

Keyboard shortcuts

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