35 lines
684 B
Go
35 lines
684 B
Go
package curre
|
|
|
|
import "context"
|
|
|
|
type FunctionalComponent struct {
|
|
InitFunc func(ctx context.Context) error
|
|
StartFunc func(ctx context.Context) error
|
|
StopFunc func(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(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
|
|
}
|