curre/builder.go

35 lines
771 B
Go
Raw Normal View History

2022-09-10 13:08:16 +02:00
package curre
import "context"
type FunctionalComponent struct {
2022-09-10 20:05:10 +02:00
InitFunc func(fc *FunctionalComponent, ctx context.Context) error
StartFunc func(fc *FunctionalComponent, ctx context.Context) error
StopFunc func(fc *FunctionalComponent, ctx context.Context) error
2022-09-10 13:08:16 +02:00
}
func NewFunctionalComponent(
2022-09-10 19:53:19 +02:00
fc *FunctionalComponent,
2022-09-10 13:08:16 +02:00
) Component {
2022-09-10 19:53:19 +02:00
return fc
2022-09-10 13:08:16 +02:00
}
2022-09-10 19:53:19 +02:00
func (fc *FunctionalComponent) Init(ctx context.Context) error {
2022-09-10 19:55:19 +02:00
if fc.InitFunc != nil {
2022-09-10 20:05:10 +02:00
return fc.InitFunc(fc, ctx)
2022-09-10 19:53:19 +02:00
}
return nil
}
func (fc *FunctionalComponent) Start(ctx context.Context) error {
2022-09-10 19:55:19 +02:00
if fc.StartFunc != nil {
2022-09-10 20:05:10 +02:00
return fc.StartFunc(fc, ctx)
2022-09-10 19:53:19 +02:00
}
return nil
}
func (fc *FunctionalComponent) Stop(ctx context.Context) error {
2022-09-10 19:55:19 +02:00
if fc.StopFunc != nil {
2022-09-10 20:05:10 +02:00
return fc.StopFunc(fc, ctx)
2022-09-10 19:53:19 +02:00
}
return nil
}