Skip to content

Commit

Permalink
Allow to override default broker for micro
Browse files Browse the repository at this point in the history
This adds an option to set an alternative Broker to avoid ocdav from
spawing the (unneeded) default http Broker.
  • Loading branch information
rhafer committed Sep 13, 2022
1 parent 0527142 commit cbe29e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/ocdav-broker-conf.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions pkg/micro/ocdav/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pkg/micro/ocdav/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cbe29e6

Please sign in to comment.