From 3b3c0e6118b62555853448695521ce9f2f2db421 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 10 Sep 2022 19:53:19 +0200 Subject: [PATCH] as function instead --- builder.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/builder.go b/builder.go index 06fb5ce..0cfc7fa 100644 --- a/builder.go +++ b/builder.go @@ -9,15 +9,26 @@ type FunctionalComponent struct { } 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.init != nil { + return fc.init(ctx) + } + return nil +} +func (fc *FunctionalComponent) Start(ctx context.Context) error { + if fc.start != nil { + return fc.start(ctx) + } + return nil +} +func (fc *FunctionalComponent) Stop(ctx context.Context) error { + if fc.stop != nil { + return fc.stop(ctx) + } + return nil +}