From 88e887100824d116accaa26adf83e3f4930c12aa Mon Sep 17 00:00:00 2001 From: noriah Date: Fri, 23 Dec 2022 16:48:25 -0800 Subject: [PATCH] rename Catnip to Run and add context param --- catnip.go | 6 +----- cmd/catnip/main.go | 6 +++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/catnip.go b/catnip.go index 9493c64..9823c35 100644 --- a/catnip.go +++ b/catnip.go @@ -14,7 +14,7 @@ type SetupFunc func() error type StartFunc func(ctx context.Context) (context.Context, error) type CleanupFunc func() error -func Catnip(cfg *Config) error { +func Run(cfg *Config, ctx context.Context) error { if err := cfg.Validate(); err != nil { return err } @@ -77,10 +77,6 @@ func Catnip(cfg *Config) error { defer cfg.CleanupFunc() } - // Root Context - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - if cfg.StartFunc != nil { if ctx, err = cfg.StartFunc(ctx); err != nil { return err diff --git a/cmd/catnip/main.go b/cmd/catnip/main.go index 8744694..f1e0bb9 100644 --- a/cmd/catnip/main.go +++ b/cmd/catnip/main.go @@ -87,7 +87,11 @@ func main() { }), } - chk(catnip.Catnip(&catnipCfg), "failed to run catnip") + // Root Context + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + chk(catnip.Run(&catnipCfg, ctx), "failed to run catnip") } func doFlags(cfg *config) bool {