environments

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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

type ConfigModule interface {
	AddFlags(fs *pflag.FlagSet)
	ReadFiles() error
}

ConfigModule values can load configuration from flags and files

type Env

type Env struct {
	Name             string
	ConfigContainer  *di.Container
	ServiceContainer *di.Container
}

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

func New(name string, options ...di.Option) (env *Env, err error)

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

func (e *Env) AddFlags(flags *pflag.FlagSet) error

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

func (env *Env) CreateServices() error

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

func (env *Env) MustResolveAll(ptrs ...di.Pointer)

func (*Env) Run

func (env *Env) Run(ctx context.Context)

Run starts the Env, waits for the context to be canceled and then stops the Env.

func (*Env) Start

func (env *Env) Start()

Start calls all the BootService.Start functions found in the container.

func (*Env) Stop

func (env *Env) Stop()

Stop calls all the BootService. Stop functions found in the dependency injection containers.

type EnvHook

type EnvHook struct {
	Func di.Invocation
}

type EnvLoader

type EnvLoader interface {
	Defaults() map[string]string
	ModifyConfiguration(env *Env) error
}

type EnvName

type EnvName string

type RouteLoader

type RouteLoader interface {
	AddRoutes(mainRouter *mux.Router) error
}

RouteLoader is load http routes into the https server's mux.Router

type ServiceProvider

type ServiceProvider interface {
	Providers() di.Option
}

type ServiceValidator

type ServiceValidator interface {
	Validate(env *Env) error
}

type SimpleEnvLoader

type SimpleEnvLoader map[string]string

func (SimpleEnvLoader) Defaults

func (b SimpleEnvLoader) Defaults() map[string]string

func (SimpleEnvLoader) ModifyConfiguration

func (b SimpleEnvLoader) ModifyConfiguration(env *Env) error

Jump to

Keyboard shortcuts

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