Documentation
¶
Index ¶
- Constants
- type Application
- type ApplicationComponents
- type ApplicationConfigInit
- type ApplicationDependencies
- type ApplicationErrorHandler
- type ApplicationIO
- type ApplicationMode
- type Component
- type ComponentComponents
- type ComponentDependencies
- type ComponentInit
- type ComponentProvider
- type ComponentStop
- type ConfigProvider
- type Dependency
- type DependencyInvoker
- type Environment
- type Processor
Constants ¶
const ( // SuccessExitCode is the exit code that the application should return // if there were no errors and the application executed successfully. SuccessExitCode int = 0 // ErrorExitCode is the exit code that the application should return if the application fails. // It can also be any number that is greater than 0 and less than 256. ErrorExitCode int = 1 )
List of default application exit codes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application interface {
// ApplicationName returns the name of the application.
ApplicationName() string
// ApplicationAction describes the main action of the current application.
// This function is called last when the application is fully initialized
ApplicationAction(env Environment, options any) (int, error)
}
Application is a general interface that application should describe.
type ApplicationComponents ¶
type ApplicationComponents interface {
// Application belongs to the application.
Application
// ApplicationComponents return a list of components that the application depends on.
// They will be sorted based on the dependent components.
ApplicationComponents() ([]Component, error)
}
ApplicationComponents is an interface that describes the components of the application.
type ApplicationConfigInit ¶
type ApplicationConfigInit interface {
// Application belongs to the application.
Application
// ApplicationConfigInit returns configuration for all application entities.
// This function is called only once.
ApplicationConfigInit(appMode ApplicationMode, options any) (map[string]any, error)
}
ApplicationConfigInit is an interface that describes the process of obtaining configuration for the application.
type ApplicationDependencies ¶
type ApplicationDependencies interface {
// Application belongs to the application.
Application
// ApplicationDependencies returns a list of dependencies that the application provides.
// This function must return an array of objects or functions that returns objects.
ApplicationDependencies() ([]Dependency, error)
}
ApplicationDependencies is an interface that describes the dependencies of the application.
type ApplicationErrorHandler ¶
type ApplicationErrorHandler interface {
// Application belongs to the application.
Application
// ApplicationErrorHandler catches all application errors that are not handled in the main application code.
ApplicationErrorHandler(err error, appIO ApplicationIO, appMode ApplicationMode) error
}
ApplicationErrorHandler is an interface that describes a function that catches all application errors.
type ApplicationIO ¶
type ApplicationIO interface {
// InputReader returns a pointer to read data into the application.
InputReader() io.Reader
// OutputWriter returns a pointer to output data from the application.
OutputWriter() io.Writer
// ErrorOutputWriter returns a pointer to output errors from the application.
ErrorOutputWriter() io.Writer
}
ApplicationIO is an interface that describes input and output for the application environment.
type ApplicationMode ¶
type ApplicationMode int
ApplicationMode is application mode type.
const ( // ProductionMode is a constant for running the application in production mode. ProductionMode ApplicationMode = 0 // DeveloperMode is a constant for running the application in developer mode. DeveloperMode ApplicationMode = 1 // TestMode is a constant for running the application in test mode. TestMode ApplicationMode = 2 )
List of default application modes.
type Component ¶
type Component interface {
// ComponentIdentifier returns the component ID.
// If the identifier in several components is the same, then the last component will be used.
// This can be used to overwrite components.
ComponentIdentifier() string
// ComponentVersion returns the component version.
ComponentVersion() string
}
Component is an interface that describes the component.
type ComponentComponents ¶
type ComponentComponents interface {
// Component belongs to the component.
Component
// ComponentComponents returns list of components that the component depends on.
// They will be sorted based on the dependent components.
ComponentComponents() ([]Component, error)
}
ComponentComponents is an interface that describes which components the current component depends on.
type ComponentDependencies ¶
type ComponentDependencies interface {
// Component belongs to the component.
Component
// ComponentDependencies returns a list of dependencies that the component provides
// This function must return an array of objects or functions that returns objects.
ComponentDependencies() ([]Dependency, error)
}
ComponentDependencies is an interface that describes the dependencies of the component.
type ComponentInit ¶
type ComponentInit interface {
// Component belongs to the component.
Component
// ComponentInit is called during component initialization.
ComponentInit(env Environment) error
}
ComponentInit is an interface that describes the component initialization.
type ComponentProvider ¶
type ComponentProvider interface {
// Components returns a list of sorted application components.
Components() []Component
}
ComponentProvider is an interface that describes a list of active application components. These components are sorted in order of dependencies between components.
type ComponentStop ¶
type ComponentStop interface {
// Component belongs to the component.
Component
// ComponentStop is called when the component stops.
// You can handle previous error (return a new or old error).
ComponentStop(env Environment, prevErr error) error
}
ComponentStop is an interface that describes stopping the component.
type ConfigProvider ¶
type ConfigProvider interface {
// ConfigValue returns the configuration by key.
// The value can be modified by the Processor which validates or converts the value.
ConfigValue(configKey string, processor Processor) (any, error)
}
ConfigProvider is an interface that describes configuration getter.
type Dependency ¶
type Dependency any
type DependencyInvoker ¶
type DependencyInvoker interface {
// Invoke uses dependencies.
// You can only pass a function as an argument.
// If the passed function returns an error, then it will be returned.
Invoke(function any) (any, error)
// Populate is similar to Invoke, but it can only take objects that are a reference.
// The passed object will be filled with dependencies.
Populate(target any) error
// PopulateFields fills the struct fields passed as an argument with dependencies.
// Fields must have a special tag: `componego:"inject"`.
// Fields without this tag are ignored.
PopulateFields(target any) error
}
DependencyInvoker is an interface that describes the functions that invoke dependencies for the application.
type Environment ¶
type Environment interface {
// GetContext returns a current application context.
GetContext() context.Context
// SetContext sets a new application context.
// The new context must inherit from the previous context.
SetContext(ctx context.Context) error
// Application returns a current application object.
Application() Application
// ApplicationIO returns an object for getting application input and output.
ApplicationIO() ApplicationIO
// ApplicationMode returns the mode in which the application is started.
ApplicationMode() ApplicationMode
// ConfigProvider returns an object for getting config.
ConfigProvider() ConfigProvider
// Components returns a sorted list of active application components.
Components() []Component
// DependencyInvoker returns an object to invoke dependencies.
DependencyInvoker() DependencyInvoker
}
Environment is an interface that describes the application environment.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
hello-app/cmd/application
command
|
|
|
hello-app/cmd/application/dev
command
|
|
|
impl
|
|
|
internal
|
|
|
libs
|
|
|
tests
|
|
