as function instead
This commit is contained in:
parent
78c0c309d7
commit
3b3c0e6118
29
builder.go
29
builder.go
@ -9,15 +9,26 @@ type FunctionalComponent struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewFunctionalComponent(
|
func NewFunctionalComponent(
|
||||||
init func(ctx context.Context) error,
|
fc *FunctionalComponent,
|
||||||
start func(ctx context.Context) error,
|
|
||||||
stop func(ctx context.Context) error,
|
|
||||||
) Component {
|
) Component {
|
||||||
return &FunctionalComponent{
|
return fc
|
||||||
init, start, stop,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc *FunctionalComponent) Init(ctx context.Context) error { return fc.init(ctx) }
|
func (fc *FunctionalComponent) Init(ctx context.Context) error {
|
||||||
func (fc *FunctionalComponent) Start(ctx context.Context) error { return fc.start(ctx) }
|
if fc.init != nil {
|
||||||
func (fc *FunctionalComponent) Stop(ctx context.Context) error { return fc.stop(ctx) }
|
return fc.init(ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (fc *FunctionalComponent) Start(ctx context.Context) error {
|
||||||
|
if fc.start != nil {
|
||||||
|
return fc.start(ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (fc *FunctionalComponent) Stop(ctx context.Context) error {
|
||||||
|
if fc.stop != nil {
|
||||||
|
return fc.stop(ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user