Documentation ¶
Overview ¶
The package try to normalize how an application should start without providing any convention about how each steps should be used.
The process will go through 6 steps:
- Init: Initialize application: register flags, no logic should be done here
- Register : Register components that does not required configuration settings
- Config : Read configuration
- Prepare : Defined main services from this configuration
- Run : Run the main program loop, each function will be run in a goroutine
- Exit : Register function call when the program will exit
Index ¶
- Constants
- func LoadConfigurationFromFile(path string) (string, error)
- func LoadConfigurationFromString(data string) (string, error)
- func PanicIf(b bool, message string)
- func PanicOnError(err error)
- func PanicUnless(b bool, message string)
- type App
- type AppFunc
- type GoroutineState
- type Lifecycle
- type LifecycleFun
- type LifecycleRunFun
Constants ¶
const ( Init = 10 // Initialize application: register flags, no logic should be done here Register = 20 // Register components that does not required configuration settings Config = 30 // Read configuration Prepare = 40 // Defined main services from configuration Run = 50 // Run the main program loop Exit = 60 // Exit the program Terminated = 70 // Exit the program )
const ( Control_End = 0 // process is stopped Control_Error = 1 // process generated an error Control_Stop = 2 // process required to stop the application Control_Kill = 3 // process required to kill the application )
Variables ¶
This section is empty.
Functions ¶
func LoadConfigurationFromFile ¶
helper function to load a configuration file as template, and replace {{ env 'ENV_VARIABLE' }} with the variable from the environnement
func LoadConfigurationFromString ¶
helper function to load a configuration string as template, and replace {{ env 'ENV_VARIABLE' }} with the variable from the environnement
func PanicOnError ¶
func PanicOnError(err error)
func PanicUnless ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
The structure contains all services build by the AppFunc function, the service is initialized when get Get method is called.
func (*App) IsTerminated ¶
type GoroutineState ¶
type GoroutineState struct { In chan int // allow a goroutine to receive a stop/exit signal Out chan int // allow a goroutine to send an exit command Error error // store any error available while running the Process }
func NewGoroutineState ¶
func NewGoroutineState() *GoroutineState
func (*GoroutineState) Close ¶
func (s *GoroutineState) Close()
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
func NewLifecycle ¶
func NewLifecycle() *Lifecycle
func (*Lifecycle) Config ¶
func (l *Lifecycle) Config(f LifecycleFun)
func (*Lifecycle) Exit ¶
func (l *Lifecycle) Exit(f LifecycleFun)
func (*Lifecycle) Go ¶
Start the different step, each LifecycleFun defined in the "run" step will be started in a dedicated goroutine. The Go function will return the exit code of the program
func (*Lifecycle) Init ¶
func (l *Lifecycle) Init(f LifecycleFun)
func (*Lifecycle) Prepare ¶
func (l *Lifecycle) Prepare(f LifecycleFun)
func (*Lifecycle) Register ¶
func (l *Lifecycle) Register(f LifecycleFun)
func (*Lifecycle) Run ¶
func (l *Lifecycle) Run(f LifecycleRunFun)
type LifecycleFun ¶
Represents the function used to change states or start a process. Please note the process should be blocking as it will run inside a goroutine
type LifecycleRunFun ¶
type LifecycleRunFun func(app *App, state *GoroutineState) error