Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
44218ec4ac
|
|||
a2c53271e4
|
|||
3b3c0e6118
|
35
builder.go
35
builder.go
@@ -3,21 +3,32 @@ package curre
|
|||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
type FunctionalComponent struct {
|
type FunctionalComponent struct {
|
||||||
init func(ctx context.Context) error
|
InitFunc func(fc *FunctionalComponent, ctx context.Context) error
|
||||||
start func(ctx context.Context) error
|
StartFunc func(fc *FunctionalComponent, ctx context.Context) error
|
||||||
stop func(ctx context.Context) error
|
StopFunc func(fc *FunctionalComponent, ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
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.InitFunc != nil {
|
||||||
func (fc *FunctionalComponent) Stop(ctx context.Context) error { return fc.stop(ctx) }
|
return fc.InitFunc(fc, ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (fc *FunctionalComponent) Start(ctx context.Context) error {
|
||||||
|
if fc.StartFunc != nil {
|
||||||
|
return fc.StartFunc(fc, ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (fc *FunctionalComponent) Stop(ctx context.Context) error {
|
||||||
|
if fc.StopFunc != nil {
|
||||||
|
return fc.StopFunc(fc, ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user