From 9d1515e8fcd34c098d2bece9c9ec34aa2ff07081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 13:37:39 +0200 Subject: [PATCH] rely on 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/activitylog/pkg/command/server.go | 7 +------ services/antivirus/pkg/command/server.go | 9 ++------- services/audit/pkg/command/server.go | 7 +------ services/clientlog/pkg/command/server.go | 7 +------ services/collaboration/pkg/command/server.go | 7 +------ services/eventhistory/pkg/command/server.go | 9 ++------- services/graph/pkg/command/server.go | 7 +------ services/idm/pkg/command/resetpw.go | 7 +------ services/idm/pkg/command/server.go | 7 +------ services/idp/pkg/command/server.go | 9 ++------- services/invitations/pkg/command/server.go | 9 ++------- services/nats/pkg/command/server.go | 7 +------ services/notifications/pkg/command/server.go | 8 +------- services/ocs/pkg/command/server.go | 9 ++------- services/policies/pkg/command/server.go | 9 ++------- services/postprocessing/pkg/command/server.go | 12 +++--------- services/proxy/pkg/command/server.go | 7 +------ services/search/pkg/command/server.go | 7 +------ services/settings/pkg/command/server.go | 7 +------ services/sse/pkg/command/server.go | 9 ++------- services/store/pkg/command/server.go | 12 ++---------- services/thumbnails/pkg/command/server.go | 11 +++-------- services/userlog/pkg/command/server.go | 7 +------ services/web/pkg/command/server.go | 11 +++-------- services/webdav/pkg/command/server.go | 9 ++------- services/webfinger/pkg/command/server.go | 9 ++------- 26 files changed, 42 insertions(+), 177 deletions(-) diff --git a/services/activitylog/pkg/command/server.go b/services/activitylog/pkg/command/server.go index e6854065c8..4f9d7d1d4d 100644 --- a/services/activitylog/pkg/command/server.go +++ b/services/activitylog/pkg/command/server.go @@ -61,12 +61,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 32e2fd8b44..0acbd87321 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -29,13 +29,8 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - logger = log.NewLogger( + ctx, cancel = context.WithCancel(c.Context) + logger = log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 6c55e638c1..aeaf01128f 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -34,12 +34,7 @@ func Server(cfg *config.Config) *cli.Command { gr = run.Group{} logger = logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel = context.WithCancel(c.Context) ) defer cancel() diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 29cfaf6cf8..b87ec8f231 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -62,12 +62,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index 5732c55890..799448d4cf 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -36,12 +36,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() // prepare components diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 197e07ae8b..1c9146aa75 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -47,13 +47,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - m = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + m = metrics.New() ) defer cancel() diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 2c547aefeb..0cde2d4db4 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -35,12 +35,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() defer cancel() diff --git a/services/idm/pkg/command/resetpw.go b/services/idm/pkg/command/resetpw.go index 0fd204c501..bdc3704486 100644 --- a/services/idm/pkg/command/resetpw.go +++ b/services/idm/pkg/command/resetpw.go @@ -40,12 +40,7 @@ func ResetPassword(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() return resetPassword(ctx, logger, cfg, c.String("user-name")) diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 048ef8d3b6..16e8a081fe 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -40,12 +40,7 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} logger = logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel = context.WithCancel(c.Context) ) defer cancel() diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index 48f431f592..78f658f146 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -56,13 +56,8 @@ func Server(cfg *config.Config) *cli.Command { } var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index 01000c7d72..183627c2d2 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -37,13 +37,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New(metrics.Logger(logger)) + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New(metrics.Logger(logger)) ) defer cancel() diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index e118d43312..f7b00f2934 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -33,12 +33,7 @@ func Server(cfg *config.Config) *cli.Command { logger := logging.Configure(cfg.Service.Name, cfg.Log) gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 55b3c7ad3c..0b635a2a2a 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -53,13 +53,7 @@ func Server(cfg *config.Config) *cli.Command { gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - + ctx, cancel := context.WithCancel(c.Context) defer cancel() { diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index cdb2311633..4a70945a8c 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -42,13 +42,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 6f4729f691..5719335ae2 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -35,13 +35,8 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - logger = log.NewLogger( + ctx, cancel = context.WithCancel(c.Context) + logger = log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index f5033c1234..5ccf65e6c1 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -36,15 +36,9 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var ( - gr = run.Group{} - logger = logging.Configure(cfg.Service.Name, cfg.Log) - - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + gr = run.Group{} + logger = logging.Configure(cfg.Service.Name, cfg.Log) + ctx, cancel = context.WithCancel(c.Context) ) defer cancel() diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index beb83ae506..2d02094a93 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -120,12 +120,7 @@ func Server(cfg *config.Config) *cli.Command { m := metrics.New() gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index 4983ab9a83..1e823e42e4 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -41,12 +41,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() mtrcs := metrics.New() diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index bcdb7f247d..73cbe437fe 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -44,12 +44,7 @@ func Server(cfg *config.Config) *cli.Command { } servers := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() mtrcs := metrics.New() diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index ac027d606d..06491d2906 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -37,13 +37,8 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - logger = log.NewLogger( + ctx, cancel = context.WithCancel(c.Context) + logger = log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), diff --git a/services/store/pkg/command/server.go b/services/store/pkg/command/server.go index 854bf0e7bb..9d32b3194c 100644 --- a/services/store/pkg/command/server.go +++ b/services/store/pkg/command/server.go @@ -35,9 +35,6 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - if err != nil { - return err - } cfg.GrpcClient, err = ogrpc.NewClient( append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(traceProvider))..., ) @@ -47,13 +44,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index ba869dae9d..ea9288a55c 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -29,7 +29,7 @@ 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) @@ -43,13 +43,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - m = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + m = metrics.New() ) defer cancel() diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index a0d2e99660..2535c38177 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -70,12 +70,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index a4423d0fe3..2c3adfb214 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -27,7 +27,7 @@ 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 { @@ -49,13 +49,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - m = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + m = metrics.New() ) defer cancel() diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index 88983e1de7..34e2b0737f 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -44,13 +44,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index 2d8c4b8e45..b0e3453d7c 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -38,13 +38,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - m = metrics.New(metrics.Logger(logger)) + ctx, cancel = context.WithCancel(c.Context) + m = metrics.New(metrics.Logger(logger)) ) defer cancel()