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 35ec85888a..ff001ad9ad 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 d540c4a5be..61a27a3c0b 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 e13d1e0154..3ba0674a85 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 c3b51a1b35..dd0f247e59 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 0fa78ee0db..d2e8863486 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 2e27fceb42..070b00a6df 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 ad28f3c79d..05e0ca124d 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 f7e6f9d7bd..83c011be6d 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 69b7215d0f..3bdf022704 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 33bb9b3226..e7573be410 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 43a2b7cdec..6dd6f8f2fc 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 bd50fff778..d7e4ba47de 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 885c445384..3c3bacc701 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 e6603064bd..1e2a8745fb 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 7843c6b2b2..f09e2f1f6a 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 770428e874..444ce0a6dd 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 dac9cf08b9..2b96aac547 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) - }() -}