diff --git a/builder.go b/builder.go new file mode 100644 index 0000000..06fb5ce --- /dev/null +++ b/builder.go @@ -0,0 +1,23 @@ +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 +} + +func NewFunctionalComponent( + init func(ctx context.Context) error, + start func(ctx context.Context) error, + stop func(ctx context.Context) error, +) Component { + return &FunctionalComponent{ + init, start, stop, + } +} + +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) } diff --git a/closers.go b/closers.go index a9d84a3..5475ef6 100644 --- a/closers.go +++ b/closers.go @@ -2,6 +2,6 @@ package curre import "context" -type Closer interface { - Close(ctx context.Context) error +type Stopper interface { + Stop(ctx context.Context) error } diff --git a/component.go b/component.go index d7b4843..6dfe11e 100644 --- a/component.go +++ b/component.go @@ -3,5 +3,5 @@ package curre type Component interface { Initer Starter - Closer + Stopper } diff --git a/example/app/main.go b/example/app/main.go index 3a312d5..4221ec0 100644 --- a/example/app/main.go +++ b/example/app/main.go @@ -28,6 +28,6 @@ func (hs *httpServer) Start(ctx context.Context) error { return nil } -func (hs *httpServer) Close(ctx context.Context) error { +func (hs *httpServer) Stop(ctx context.Context) error { return nil } diff --git a/manager.go b/manager.go index 96a653e..d5eba54 100644 --- a/manager.go +++ b/manager.go @@ -139,7 +139,7 @@ func (m *Manager) shutdown(ctx context.Context) error { go func(ctx context.Context) { for _, c := range closers { - c.Close(ctx) + c.Stop(ctx) } shutdownChan <- struct{}{}