replace defineContext with context from app

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2024-07-24 13:33:57 +02:00
parent 008f379a01
commit a96203786f
17 changed files with 18 additions and 205 deletions

View File

@@ -39,7 +39,7 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
gr := run.Group{}
ctx, cancel := defineContext(cfg)
ctx, cancel := context.WithCancel(c.Context)
defer cancel()
@@ -104,14 +104,3 @@ func Server(cfg *config.Config) *cli.Command {
},
}
}
// defineContext sets the context for the service. If there is a context configured it will create a new child from it,
// if not, it will create a root context that can be cancelled.
func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) {
return func() (context.Context, context.CancelFunc) {
if cfg.Context == nil {
return context.WithCancel(context.Background())
}
return context.WithCancel(cfg.Context)
}()
}