From a96203786fc725073a52a912faa3d1bd990dabd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 13:33:57 +0200 Subject: [PATCH] replace defineContext with context from app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/app-provider/pkg/command/server.go | 13 +------------ services/app-registry/pkg/command/server.go | 13 +------------ services/auth-app/pkg/command/server.go | 15 ++------------- services/auth-basic/pkg/command/server.go | 13 +------------ services/auth-bearer/pkg/command/server.go | 13 +------------ services/auth-machine/pkg/command/server.go | 13 +------------ services/auth-service/pkg/command/server.go | 13 +------------ services/frontend/pkg/command/server.go | 13 +------------ services/groups/pkg/command/server.go | 13 +------------ services/ocdav/pkg/command/server.go | 13 +------------ services/ocm/pkg/command/server.go | 13 +------------ services/sharing/pkg/command/server.go | 13 +------------ services/storage-publiclink/pkg/command/server.go | 13 +------------ services/storage-shares/pkg/command/server.go | 13 +------------ services/storage-system/pkg/command/server.go | 13 +------------ services/storage-users/pkg/command/server.go | 13 +------------ services/users/pkg/command/server.go | 13 +------------ 17 files changed, 18 insertions(+), 205 deletions(-) diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 35ec85888..ff001ad9a 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -38,7 +38,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() @@ -91,14 +91,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) - }() -} diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index d540c4a5b..61a27a3c0 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -37,7 +37,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() @@ -86,14 +86,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) - }() -} diff --git a/services/auth-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index e13d1e015..3ba0674a8 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -31,14 +31,14 @@ func Server(cfg *config.Config) *cli.Command { Before: func(_ *cli.Context) error { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, - Action: func(_ *cli.Context) error { + Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -91,14 +91,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) - }() -} diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index c3b51a1b3..dd0f247e5 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -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) - }() -} diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 0fa78ee0d..d2e886348 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -38,7 +38,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() @@ -91,14 +91,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) - }() -} diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index 2e27fceb4..070b00a6d 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -38,7 +38,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() @@ -91,14 +91,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) - }() -} diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index ad28f3c79..05e0ca124 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -38,7 +38,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() @@ -92,14 +92,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) - }() -} diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index f7e6f9d7b..83c011be6 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -38,7 +38,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() @@ -102,14 +102,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) - }() -} diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 69b7215d0..3bdf02270 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -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) - }() -} diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 33bb9b322..e7573be41 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -36,7 +36,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() @@ -127,14 +127,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) - }() -} diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 43a2b7cde..6dd6f8f2f 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -38,7 +38,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() @@ -97,14 +97,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) - }() -} diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index bd50fff77..d7e4ba47d 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -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() @@ -108,14 +108,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) - }() -} diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 885c44538..3c3bacc70 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -38,7 +38,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() @@ -91,14 +91,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) - }() -} diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index e6603064b..1e2a8745f 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -38,7 +38,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() @@ -91,14 +91,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) - }() -} diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 7843c6b2b..f09e2f1f6 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -38,7 +38,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() @@ -96,14 +96,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) - }() -} diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index 770428e87..444ce0a6d 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -40,7 +40,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() @@ -128,14 +128,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) - }() -} diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index dac9cf08b..2b96aac54 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -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) - }() -}