From cbe29e69424d990a9a526b6f271d483d4bd6faa1 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Tue, 13 Sep 2022 16:09:43 +0200 Subject: [PATCH] Allow to override default broker for micro This adds an option to set an alternative Broker to avoid ocdav from spawing the (unneeded) default http Broker. --- changelog/unreleased/ocdav-broker-conf.md | 6 ++++++ pkg/micro/ocdav/option.go | 9 +++++++++ pkg/micro/ocdav/service.go | 1 + 3 files changed, 16 insertions(+) create mode 100644 changelog/unreleased/ocdav-broker-conf.md diff --git a/changelog/unreleased/ocdav-broker-conf.md b/changelog/unreleased/ocdav-broker-conf.md new file mode 100644 index 0000000000..bc4d687d84 --- /dev/null +++ b/changelog/unreleased/ocdav-broker-conf.md @@ -0,0 +1,6 @@ +Enhancement: Allow to override default broker for go-micro base ocdav service + +An option for setting an alternative go-micro Broker was introduced. This can +be used to avoid ocdav from spawing the (unneeded) default http Broker. + +https://github.com/cs3org/reva/pull/3233 diff --git a/pkg/micro/ocdav/option.go b/pkg/micro/ocdav/option.go index 2c94830440..d63ed733e1 100644 --- a/pkg/micro/ocdav/option.go +++ b/pkg/micro/ocdav/option.go @@ -25,6 +25,7 @@ import ( "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav" "github.com/cs3org/reva/v2/pkg/storage/favorite" "github.com/rs/zerolog" + "go-micro.dev/v4/broker" ) // Option defines a single option function. @@ -33,6 +34,7 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { TLSConfig *tls.Config + Broker broker.Broker Address string Logger zerolog.Logger Context context.Context @@ -70,6 +72,13 @@ func TLSConfig(config *tls.Config) Option { } } +// Broker provides a function to set the Broker option. +func Broker(b broker.Broker) Option { + return func(o *Options) { + o.Broker = b + } +} + // Address provides a function to set the address option. func Address(val string) Option { return func(o *Options) { diff --git a/pkg/micro/ocdav/service.go b/pkg/micro/ocdav/service.go index 52f377ca9d..2de25ebb2c 100644 --- a/pkg/micro/ocdav/service.go +++ b/pkg/micro/ocdav/service.go @@ -57,6 +57,7 @@ func Service(opts ...Option) (micro.Service, error) { sopts.Logger = sopts.Logger.With().Str("name", sopts.Name).Logger() srv := httpServer.NewServer( + server.Broker(sopts.Broker), server.TLSConfig(sopts.TLSConfig), server.Name(sopts.Name), server.Address(sopts.Address), // Address defaults to ":0" and will pick any free port