Documentation
¶
Overview ¶
Package application provides the high-level application bootstrap, module registration, and run modes.
Index ¶
- Constants
- func NewSignalContext() (context.Context, context.CancelFunc)
- func ProcessRoleMustFromContainer(serviceContainer containercontract.Container) string
- func ProcessRoleMustFromResolver(resolver containercontract.Resolver) string
- type Application
- func (instance *Application) Boot() kernelcontract.Kernel
- func (instance *Application) Close()
- func (instance *Application) Configuration() configcontract.Configuration
- func (instance *Application) OnHttpShutdown(hook func())
- func (instance *Application) ProcessRole() string
- func (instance *Application) RegisterCliCommand(command clicontract.Command)
- func (instance *Application) RegisterConfiguration(name string, configuration any)
- func (instance *Application) RegisterHttpHandlerDecorator(decorator applicationcontract.HttpHandlerDecorator)
- func (instance *Application) RegisterHttpMiddlewareFactories(factories ...MiddlewareFactory)
- func (instance *Application) RegisterHttpMiddlewares(middlewares ...httpcontract.Middleware)
- func (instance *Application) RegisterHttpRoute(method string, pattern string, handler httpcontract.Handler)
- func (instance *Application) RegisterModule(moduleInstance applicationcontract.Module)
- func (instance *Application) RegisterModuleProvider(provider applicationcontract.ModuleProvider)
- func (instance *Application) RegisterParameter(name string, value any)
- func (instance *Application) RegisterService(serviceName string, provider any, options ...containercontract.RegisterOption)
- func (instance *Application) Run()
- type HttpMiddleware
- func (instance *HttpMiddleware) LastBuildReport() *middlewarepipeline.MiddlewareBuildReport
- func (instance *HttpMiddleware) Use(middlewares ...httpcontract.Middleware)
- func (instance *HttpMiddleware) UseFactories(factories ...MiddlewareFactory)
- func (instance *HttpMiddleware) UseFactoriesWithPriority(priority int, factories ...MiddlewareFactory)
- func (instance *HttpMiddleware) UseWithPriority(priority int, middlewares ...httpcontract.Middleware)
- type HttpShutdownConfiguration
- type HttpTimeoutConfiguration
- type MiddlewareFactory
- type RouteRegistrar
- type RuntimeFlags
- type SecurityModule
Constants ¶
const ( MiddlewareGroupHttp = "http" MiddlewarePriorityStatic = -1000 MiddlewareNameStatic = "static" MiddlewarePriorityDefault = 0 )
const ServiceProcessRole = "service.application.process_role"
ServiceProcessRole resolves to the process role string (config.RoleWeb, config.RoleWorker or config.RoleAll) so services can gate background work without reaching back to the application instance.
Variables ¶
This section is empty.
Functions ¶
func NewSignalContext ¶
func NewSignalContext() (context.Context, context.CancelFunc)
func ProcessRoleMustFromContainer ¶ added in v3.10.0
func ProcessRoleMustFromContainer(serviceContainer containercontract.Container) string
func ProcessRoleMustFromResolver ¶ added in v3.10.0
func ProcessRoleMustFromResolver(resolver containercontract.Resolver) string
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func NewApplication ¶
func (*Application) Boot ¶
func (instance *Application) Boot() kernelcontract.Kernel
func (*Application) Close ¶
func (instance *Application) Close()
func (*Application) Configuration ¶ added in v3.9.0
func (instance *Application) Configuration() configcontract.Configuration
Configuration exposes the loaded configuration before boot so wiring code (module
construction in the composition root) can read parameters — including the values melody auto-registers from the .env files — without reaching for os.Getenv. Services resolved from the container should instead read config through the resolver.
func (*Application) OnHttpShutdown ¶ added in v3.10.0
func (instance *Application) OnHttpShutdown(hook func())
OnHttpShutdown registers a callback that runs as soon as the http server begins shutting down, before it waits for connections to drain. It is how an application unwinds handlers the server cannot: `http.Server.Shutdown` neither cancels the contexts of in-flight requests nor tracks hijacked connections, so a Server-Sent Events stream or a websocket blocks the whole shutdown timeout and is then cut mid-flight. Closing the hub those handlers select on (`ServerSentEventHub.Shutdown`) releases them at once.
func (*Application) ProcessRole ¶ added in v3.10.0
func (instance *Application) ProcessRole() string
ProcessRole is the resolved process role (config.RoleWeb, config.RoleWorker or config.RoleAll): an explicit --role flag wins over the MELODY_PROCESS_ROLE parameter, which defaults to all. Melody gates nothing on it — wiring code queries it to decide whether to register background runners (outbox relays, consumers) on this process; services resolve the same value through ServiceProcessRole.
func (*Application) RegisterCliCommand ¶
func (instance *Application) RegisterCliCommand(command clicontract.Command)
func (*Application) RegisterConfiguration ¶ added in v3.1.0
func (instance *Application) RegisterConfiguration(name string, configuration any)
func (*Application) RegisterHttpHandlerDecorator ¶ added in v3.9.0
func (instance *Application) RegisterHttpHandlerDecorator(decorator applicationcontract.HttpHandlerDecorator)
RegisterHttpHandlerDecorator adds an outermost wrapper around the nethttp.Handler the http kernel produces. Decorators observe the full request lifecycle — including security denials and other kernel.request short-circuits that never reach the middlewares — which is where observability wrappers belong. The first registered decorator is the outermost.
func (*Application) RegisterHttpMiddlewareFactories ¶
func (instance *Application) RegisterHttpMiddlewareFactories( factories ...MiddlewareFactory, )
func (*Application) RegisterHttpMiddlewares ¶
func (instance *Application) RegisterHttpMiddlewares(middlewares ...httpcontract.Middleware)
func (*Application) RegisterHttpRoute ¶
func (instance *Application) RegisterHttpRoute( method string, pattern string, handler httpcontract.Handler, )
func (*Application) RegisterModule ¶
func (instance *Application) RegisterModule(moduleInstance applicationcontract.Module)
func (*Application) RegisterModuleProvider ¶ added in v3.7.0
func (instance *Application) RegisterModuleProvider(provider applicationcontract.ModuleProvider)
func (*Application) RegisterParameter ¶
func (instance *Application) RegisterParameter( name string, value any, )
func (*Application) RegisterService ¶
func (instance *Application) RegisterService( serviceName string, provider any, options ...containercontract.RegisterOption, )
func (*Application) Run ¶
func (instance *Application) Run()
type HttpMiddleware ¶
type HttpMiddleware struct {
// contains filtered or unexported fields
}
func NewHttpMiddleware ¶
func NewHttpMiddleware( staticOptions *static.Options, configuration configcontract.Configuration, ) *HttpMiddleware
func (*HttpMiddleware) LastBuildReport ¶
func (instance *HttpMiddleware) LastBuildReport() *middlewarepipeline.MiddlewareBuildReport
func (*HttpMiddleware) Use ¶
func (instance *HttpMiddleware) Use(middlewares ...httpcontract.Middleware)
func (*HttpMiddleware) UseFactories ¶
func (instance *HttpMiddleware) UseFactories(factories ...MiddlewareFactory)
func (*HttpMiddleware) UseFactoriesWithPriority ¶
func (instance *HttpMiddleware) UseFactoriesWithPriority(priority int, factories ...MiddlewareFactory)
func (*HttpMiddleware) UseWithPriority ¶
func (instance *HttpMiddleware) UseWithPriority(priority int, middlewares ...httpcontract.Middleware)
type HttpShutdownConfiguration ¶ added in v3.7.0
type HttpTimeoutConfiguration ¶ added in v3.5.0
type MiddlewareFactory ¶
type MiddlewareFactory func(kernelInstance kernelcontract.Kernel) httpcontract.Middleware
type RouteRegistrar ¶
type RouteRegistrar func(kernelInstance kernelcontract.Kernel)
type RuntimeFlags ¶
type RuntimeFlags struct {
// contains filtered or unexported fields
}
func NewRuntimeFlags ¶
func NewRuntimeFlags(mode string) *RuntimeFlags
func NewRuntimeFlagsWithRole ¶ added in v3.10.0
func NewRuntimeFlagsWithRole(mode string, role string) *RuntimeFlags
func ParseRuntimeFlags ¶
func ParseRuntimeFlags(defaultMode string) *RuntimeFlags
func ParseRuntimeFlagsWithRole ¶ added in v3.10.0
func ParseRuntimeFlagsWithRole(defaultMode string, defaultRole string) *RuntimeFlags
ParseRuntimeFlagsWithRole resolves the runtime mode and process role from os.Args. The mode: an explicit --mode/-mode wins, any other non-runtime argument implies cli, otherwise the configured default applies. The role: an explicit --role/-role wins over the configured default — the flag exists because melody reads configuration only from .env artifacts, never from the process environment, so a docker-compose deployment differentiates containers built from one image with `command: ["/app", "--role=worker"]`. Both flags are runtime-only: they never imply cli mode and are stripped before the cli framework parses the arguments.
func (*RuntimeFlags) Mode ¶
func (instance *RuntimeFlags) Mode() string
func (*RuntimeFlags) Role ¶ added in v3.10.0
func (instance *RuntimeFlags) Role() string
type SecurityModule ¶
type SecurityModule interface {
applicationcontract.Module
RegisterSecurity(builder *securityconfig.Builder)
}
Source Files
¶
- application.go
- application_cli.go
- application_close.go
- application_container.go
- application_http.go
- application_http_timeouts.go
- application_module.go
- application_new.go
- boot_collision.go
- bootstrap.go
- cli.go
- doc.go
- environment_local.go
- environment_warning.go
- http_middleware.go
- security_module.go
- service_resolver.go
- signal_context.go
- static_local.go