curre/builder.go
2022-09-10 20:05:10 +02:00

35 lines
771 B
Go

package curre
import "context"
type FunctionalComponent struct {
InitFunc func(fc *FunctionalComponent, ctx context.Context) error
StartFunc func(fc *FunctionalComponent, ctx context.Context) error
StopFunc func(fc *FunctionalComponent, ctx context.Context) error
}
func NewFunctionalComponent(
fc *FunctionalComponent,
) Component {
return fc
}
func (fc *FunctionalComponent) Init(ctx context.Context) error {
if fc.InitFunc != nil {
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
}