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