Documentation
¶
Index ¶
- Variables
- type Application
- func (a *Application) Health(ctx context.Context) *ApplicationHealth
- func (a *Application) OnStart(task Runner, config StartupTaskConfig)
- func (a *Application) OnStartFunc(task RunnerFunc, config StartupTaskConfig)
- func (a *Application) RegisterDatabase(dbName string, db *database.Database)
- func (a *Application) RegisterDomain(name, dbName string, domain Domain)
- func (a *Application) RegisterRepository(dbName string, repoName string, repository any)
- func (a *Application) RegisterService(serviceName string, service Runner)
- func (a *Application) Run(ctx context.Context) error
- type ApplicationHealth
- type Domain
- type ErrDatabaseMigrationFailed
- type ErrStartupTaskFailed
- type HealthCheckHandler
- type Healthchecker
- type Runner
- type RunnerFunc
- type ServiceHealth
- type ServiceStatus
- type StartupTaskConfig
Constants ¶
This section is empty.
Variables ¶
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 (*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.
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 ErrDatabaseMigrationFailed ¶
type ErrDatabaseMigrationFailed struct {
// contains filtered or unexported fields
}
ErrDatabaseMigrationFailed is an error type that represents a failed database migration.
func (*ErrDatabaseMigrationFailed) Error ¶
func (e *ErrDatabaseMigrationFailed) Error() string
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 ¶
RunnerFunc is a function type that implements the Runner interface.
type ServiceHealth ¶
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.