diff --git a/api/layer/layer.go b/api/layer/layer.go index fec8c09cf..d0790162a 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -281,10 +281,6 @@ func (n *layer) EphemeralKey() *keys.PublicKey { } func (n *layer) Initialize(ctx context.Context, c Notificator) error { - if c == nil { - return nil - } - if n.IsNotificationEnabled() { return fmt.Errorf("already initialized") } diff --git a/api/notifications/controller.go b/api/notifications/controller.go index 4bc3f0d59..8e754cd00 100644 --- a/api/notifications/controller.go +++ b/api/notifications/controller.go @@ -37,10 +37,6 @@ type Stream struct { } func NewController(p *Options, l *zap.Logger) (*Controller, error) { - if p == nil { - return nil, nil - } - ncopts := []nats.Option{ nats.Timeout(p.Timeout), } diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index 596455033..4ec4fc920 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -57,6 +57,7 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { caller api.Handler ctr auth.Center obj layer.Client + nc *notifications.Controller poolPeers = fetchPeers(l, v) @@ -143,12 +144,6 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { l.Fatal("failed to form resolver", zap.Error(err)) } - nopts := getNotificationsOptions(v, l) - nc, err := notifications.NewController(nopts, l) - if err != nil { - l.Fatal("failed to enable notifications", zap.Error(err)) - } - layerCfg := &layer.Config{ Caches: getCacheOptions(v, l), AnonKey: layer.AnonymousKey{ @@ -160,8 +155,16 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { // prepare object layer obj = layer.NewLayer(l, &layerNeoFS{&neoFS}, layerCfg) - if err = obj.Initialize(ctx, nc); err != nil { - l.Fatal("couldn't initialize layer", zap.Error(err)) + if v.GetBool(cfgEnableNATS) { + nopts := getNotificationsOptions(v, l) + nc, err = notifications.NewController(nopts, l) + if err != nil { + l.Fatal("failed to enable notifications", zap.Error(err)) + } + + if err = obj.Initialize(ctx, nc); err != nil { + l.Fatal("couldn't initialize layer", zap.Error(err)) + } } // prepare auth center @@ -265,10 +268,6 @@ func (a *App) Server(ctx context.Context) { } func getNotificationsOptions(v *viper.Viper, l *zap.Logger) *notifications.Options { - if enabled := v.GetBool(cfgEnableNATS); !enabled { - return nil - } - cfg := notifications.Options{} cfg.URL = v.GetString(cfgNATSEndpoint) cfg.Timeout = v.GetDuration(cfgNATSTimeout)