Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Bootstrap = fx.Provide(NewLifecycle)
Bootstrap can be used as an alias for must have provider options composed into one fx option.
Functions ¶
func NewLifecycle ¶
NewLifecycle creates a new lifecycle required by all constructors providing closers. It requires an fx.Lifecycle instance to register OnStart and OnStop hooks in.
Types ¶
type App ¶ added in v0.12.0
App wraps the original fx.App instance and adds a closer method to it.
type ApplicationInfo ¶ added in v0.15.0
ApplicationInfo is an optional set of information that can be set by the runtime environment (eg. console application).
type Closer ¶
type Closer interface {
Close() error
}
Closer is the interface modelled after io.Closer for post-shutdown cleanups.
type Hook ¶
type Hook struct { OnStart func(context.Context) error OnStop func(context.Context) error OnClose func() error }
Hook is a set of callbacks extending fx.Hook. It adds an OnClose hook which allows post-shutdown cleanups.
type Lifecycle ¶
type Lifecycle interface {
Append(Hook)
}
Lifecycle extends fx.Lifecycle by adding the extra OnClose in Hook.
Example ¶
package main import ( "fmt" "github.com/goph/fxt" "go.uber.org/fx" ) func main() { var ctx struct { Closer fxt.Closer } type A struct{} fx.New( fx.Provide(fxt.NewLifecycle), fx.Provide(func(l fxt.Lifecycle) *A { l.Append(fxt.Hook{ // OnStart and OnStop are valid fx hooks as well. OnClose: func() error { fmt.Print("closing") return nil }, }) return &A{} }), fx.Extract(&ctx), fx.Invoke(func(a *A) {}), fx.NopLogger, ) defer ctx.Closer.Close() }
Output: closing
Directories ¶
Path | Synopsis |
---|---|
database
|
|
middleware/correlationid/internal/mocks
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0
|
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 |
metrics
|
|