Documentation ¶
Index ¶
- Constants
- func Func(f func() di.Option) func() ServiceProvider
- func GetEnvironmentStrFromEnv() string
- type AfterCreateServicesHook
- type BeforeCreateServicesHook
- type BootService
- type ConfigModule
- type Env
- func (e *Env) AddFlags(flags *pflag.FlagSet) error
- func (env *Env) Cleanup()
- func (env *Env) CreateServices() error
- func (env *Env) MustInvoke(invocation di.Invocation, options ...di.InvokeOption)
- func (env *Env) MustResolve(ptr di.Pointer, options ...di.ResolveOption)
- func (env *Env) MustResolveAll(ptrs ...di.Pointer)
- func (env *Env) Run(ctx context.Context)
- func (env *Env) Start()
- func (env *Env) Stop()
- type EnvHook
- type EnvLoader
- type EnvName
- type RouteLoader
- type ServiceProvider
- type ServiceValidator
- type SimpleEnvLoader
Constants ¶
const ( TestingEnv string = "testing" DevelopmentEnv string = "development" ProductionEnv string = "production" StageEnv string = "stage" IntegrationEnv string = "integration" EnvironmentStringKey string = "OCM_ENV" EnvironmentDefault = DevelopmentEnv )
Variables ¶
This section is empty.
Functions ¶
func Func ¶
func Func(f func() di.Option) func() ServiceProvider
func GetEnvironmentStrFromEnv ¶
func GetEnvironmentStrFromEnv() string
Types ¶
type AfterCreateServicesHook ¶
type AfterCreateServicesHook EnvHook
type BeforeCreateServicesHook ¶
type BeforeCreateServicesHook EnvHook
type BootService ¶
type BootService interface { Start() Stop() }
BootService are services that get started on application boot.
type ConfigModule ¶
ConfigModule values can load configuration from flags and files
type Env ¶
Env is a modular application built with dependency injection and manages applying lifecycle events of types injected into the application.
An Env uses two dependency injection containers. The first one it constructs is the ConfigContainer
func New ¶
New creates and initializes an Env with the provided name and injection options. After initialization, types in the Env.ConfigContainer can be resolved using dependency injection.
func (*Env) AddFlags ¶
AddFlags is used to allow command line flags to modify the values of types in the Env.ConfigContainer. All types in Env.ConfigContainer that implement the ConfigModule interface invoked with ConfigModule.AddFlags.
Then flag defaults will set by getting defaults for the Env.Name by looking up a EnvLoader tagged with that name in the Env.ConfigContainer.
func (*Env) Cleanup ¶
func (env *Env) Cleanup()
Cleanup calls all the cleanup functions registered with the dependency injection containers.
func (*Env) CreateServices ¶
CreateServices loads, creates, and validates the applications services.
This should be called after the environment has been configured appropriately though AddFlags and parsing, done elsewhere.
The function will look for many inject types in dependency injection container and called them in this order: 1) All ConfigModule.ReadFiles functions - to load file system based configuration. 2) The EnvLoader.ModifyConfiguration function - to allow named environment to apply configuration changes (TODO: replace with a BeforeCreateServicesHook??) 3) All BeforeCreateServicesHook.Func functions - configuration hooks 4) All ServiceProvider.Providers functions - to collect al dependency injection objects use to construct the Env.ServiceContainer 5) The Env.ServiceContainer is created 6) All ServiceValidator.Validate functions - used to validate the configuration or service types (TODO: replace with a AfterCreateServicesHook??) 7) All AfterCreateServicesHook.Func functions - a hook that is called after the service container is created.
func (*Env) MustInvoke ¶
func (env *Env) MustInvoke(invocation di.Invocation, options ...di.InvokeOption)
func (*Env) MustResolve ¶
func (env *Env) MustResolve(ptr di.Pointer, options ...di.ResolveOption)
func (*Env) MustResolveAll ¶
type EnvHook ¶
type EnvHook struct {
Func di.Invocation
}
type RouteLoader ¶
RouteLoader is load http routes into the https server's mux.Router
type ServiceProvider ¶
type ServiceValidator ¶
type SimpleEnvLoader ¶
func (SimpleEnvLoader) Defaults ¶
func (b SimpleEnvLoader) Defaults() map[string]string
func (SimpleEnvLoader) ModifyConfiguration ¶
func (b SimpleEnvLoader) ModifyConfiguration(env *Env) error