application

package
v0.1.0-alpha.19 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownCommand = errors.New("unknown command")

ErrUnknownCommand is returned when an unknown CLI command is provided.

Functions

This section is empty.

Types

type Application

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

Application manages startup tasks and services for the application lifecycle.

func New

func New() *Application

New creates and returns a new Application instance.

func (*Application) Health

func (a *Application) Health(ctx context.Context) *ApplicationHealth

Health returns the current health status of the application.

func (*Application) OnStart

func (a *Application) OnStart(task Runner, config StartupTaskConfig)

OnStart registers a new startup task with the given runner and configuration.

func (*Application) OnStartFunc

func (a *Application) OnStartFunc(task RunnerFunc, config StartupTaskConfig)

func (*Application) RegisterDatabase

func (a *Application) RegisterDatabase(dbName string, db *database.Database)

RegisterDatabase adds a database to the application.

func (*Application) RegisterDomain

func (a *Application) RegisterDomain(name, dbName string, domain Domain)

func (*Application) RegisterRepository

func (a *Application) RegisterRepository(dbName string, repoName string, repository any)

RegisterRepository adds a repository to the application.

func (*Application) RegisterService

func (a *Application) RegisterService(serviceName string, service Runner)

RegisterService adds a named service to the application.

func (*Application) Run

func (a *Application) Run(ctx context.Context) error

Run parses CLI arguments and executes the appropriate command. Supported commands: run (start services), migrate (run database migrations). Returns nil on success, ErrUnknownCommand for unknown commands.

type ApplicationHealth

type ApplicationHealth struct {
	StartedAt time.Time                 `json:"startedAt"`
	Services  map[string]*ServiceHealth `json:"services"`
}

func NewApplicationHealth

func NewApplicationHealth() *ApplicationHealth

func (*ApplicationHealth) FailService

func (h *ApplicationHealth) FailService(serviceName string, err error)

func (*ApplicationHealth) SetServiceData

func (h *ApplicationHealth) SetServiceData(serviceName string, data any)

func (*ApplicationHealth) StartApplication

func (h *ApplicationHealth) StartApplication()

func (*ApplicationHealth) StartService

func (h *ApplicationHealth) StartService(serviceName string)

func (*ApplicationHealth) String

func (h *ApplicationHealth) String() string

type Domain

type Domain interface {
	GetRepository() any
}

type ErrDatabaseMigrationFailed

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

ErrDatabaseMigrationFailed is an error type that represents a failed database migration.

func (*ErrDatabaseMigrationFailed) Error

Error returns the formatted error message for ErrDatabaseMigrationFailed.

func (*ErrDatabaseMigrationFailed) Unwrap

func (e *ErrDatabaseMigrationFailed) Unwrap() error

Unwrap returns the underlying error for ErrDatabaseMigrationFailed.

type ErrStartupTaskFailed

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

ErrStartupTaskFailed represents an error that occurs when a startup task fails.

func (*ErrStartupTaskFailed) Error

func (e *ErrStartupTaskFailed) Error() string

Error returns the formatted error message for ErrStartupTaskFailed.

func (*ErrStartupTaskFailed) Unwrap

func (e *ErrStartupTaskFailed) Unwrap() error

Unwrap returns the underlying error for ErrStartupTaskFailed.

type HealthCheckHandler

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

func NewHealthCheckHandler

func NewHealthCheckHandler(app healther) *HealthCheckHandler

func (*HealthCheckHandler) ServeHTTP

func (h *HealthCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Healthchecker

type Healthchecker interface {
	// Healthcheck returns the health status of the service.
	Healthcheck(context.Context) any
}

Healthchecker represents a service that can perform health checks.

type Runner

type Runner interface {
	// Run executes the task with the given context and returns an error if any.
	Run(context.Context) error
}

Runner is an interface that defines the Run method for executing a task with context.

type RunnerFunc

type RunnerFunc func(context.Context) error

RunnerFunc is a function type that implements the Runner interface.

func (RunnerFunc) Run

func (rf RunnerFunc) Run(ctx context.Context) error

Run executes the RunnerFunc with the given context and returns the result.

type ServiceHealth

type ServiceHealth struct {
	Status    ServiceStatus `json:"status"`
	StartedAt *time.Time    `json:"startedAt"`
	StoppedAt *time.Time    `json:"stoppedAt,omitempty"`
	Error     string        `json:"error,omitempty"`
	Data      any           `json:"data,omitempty"`
}

type ServiceStatus

type ServiceStatus string
const (
	ServiceStatusNotStarted ServiceStatus = "NOT_STARTED"
	ServiceStatusStarted    ServiceStatus = "STARTED"
	ServiceStatusError      ServiceStatus = "ERROR"
)

type StartupTaskConfig

type StartupTaskConfig struct {
	Name         string // Name of the startup task
	AbortOnError bool   // Whether to abort application startup if this task fails
}

StartupTaskConfig contains configuration options for a startup task.

Jump to

Keyboard shortcuts

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