Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is a primary microservice abstraction.
func (*App) Conn ¶
func (a *App) Conn(components []Component, asyncComponents []AsyncComponent)
Conn connects louse coupled Components and AsyncComponents with an application. Later components will initialize and run/asyncRun in the order of place in a slice.
Example:
var application App application.Conn( []Component{ logger.NewComponent(), config.NewComponent(), }, []AsyncComponent{ metrics.NewComponent(), }, )
func (App) Init ¶
func (a App) Init()
Init calls the Init() method for all Components and AsyncComponents. Components can return an error when something goes bad. Errors returned by components do not handling and crash the entire application. You should use recover() func to prevent the application crash.
Example:
var application App
application.Conn(
[]Component{ logger.NewComponent(), tracer.NewComponent(), }, []AsyncComponent{ handler.NewComponent(), metrics.NewComponent(), }, )
application.Init()
Example with recovering:
var application App
defer func() { err := recover() if err != nil { fmt.Println("Microservice will not crash!") } }()
application.Conn(
[]Component{ logger.NewComponent(), tracer.NewComponent(), }, []AsyncComponent{ handler.NewComponent(), metrics.NewComponent(), }, )
application.Init() .
func (App) Run ¶
func (a App) Run()
Run calls the Run() method for all Components and AsyncComponents. Components can return an error when something goes bad. Errors returned by components do not handling and crash the entire application. You should use recover() func to prevent the application crash.
Example:
var application App
application.Conn(
[]Component{ logger.NewComponent(), tracer.NewComponent(), }, []AsyncComponent{ handler.NewComponent(), metrics.NewComponent(), }, )
application.Init() application.Run()
Example with recovering:
var application App
defer func() { err := recover() if err != nil { fmt.Println("Microservice will not crash!") } }()
application.Conn(
[]Component{ logger.NewComponent(), tracer.NewComponent(), }, []AsyncComponent{ handler.NewComponent(), metrics.NewComponent(), }, )
application.Init() application.Run() .
type AsyncComponent ¶
type AsyncComponent interface { Initializer AsyncRunner }
type AsyncRunner ¶
type Component ¶
type Component interface { Initializer Runner }
type Initializer ¶
type Initializer interface {
Init() error
}