Skip to main content
The application package provides the core Application type that manages startup tasks, services, databases, and health checks throughout your application’s lifecycle.

Application Type

The Application type orchestrates the lifecycle of your application, managing startup tasks, services, databases, and health monitoring.

Constructor

*Application
Creates and returns a new Application instance.

Methods

RegisterService

void
Registers a named service with the application. Services are started concurrently when the application runs.

RegisterDatabase

void
Adds a database to the application for lifecycle management.

RegisterRepository

void
Registers a repository with a specific database. Repositories implementing the migrator interface will have their migrations applied.

RegisterDomain

void
Registers a domain repository in the specified database. The domain must implement the Domain interface.

OnStart

void
Registers a startup task that runs before services start.

OnStartFunc

void
Registers a startup task using a function.

Health

*Health
Returns the current health status of the application and all registered services.

Run

error
Parses CLI arguments and executes the appropriate command.Supported commands:
  • run - Starts all registered services
  • migrate - Runs database migrations
  • --help, -h - Displays usage information
Returns ErrUnknownCommand if an unknown command is provided.

Interfaces

Runner

The Runner interface defines tasks that can be executed with context.
func(context.Context) error
Executes the task with the given context and returns an error if any.

RunnerFunc

A function type that implements the Runner interface.

Domain

The Domain interface describes a domain module that exposes its repository.
func() any
Returns the repository associated with this domain.

Healthchecker

Represents a service that can perform health checks.
func(context.Context) any
Returns the health status of the service. The returned value can be any serializable type.

Types

StartupTaskConfig

Configuration options for a startup task.
string
Name of the startup task for logging and identification.
bool
If true, the application will terminate if this startup task fails. If false, the error is logged and execution continues.

Errors

ErrUnknownCommand

Returned when an unknown CLI command is provided to Run().

ErrDatabaseMigrationFailed

Returned when database migration fails during the migrate command.

ErrStartupTaskFailed

Returned when a startup task with AbortOnError: true fails.

Helpers

HealthCheckHandler

An HTTP handler that serves application health information as JSON.
*HealthCheckHandler
Creates a health check HTTP handler for the application.Parameters:
  • app (*Application): The application instance to check health for
The handler returns a JSON response with:
  • Application start time
  • Service statuses (NOT_STARTED, STARTED, ERROR)
  • Service start/stop times
  • Error messages for failed services
  • Custom health data from Healthchecker implementations

Example Usage

CLI Usage: