From cbc2cbd27039a16ee33e1db605aa8f7b2a63853e Mon Sep 17 00:00:00 2001 From: maura fortino Date: Wed, 1 May 2024 14:51:17 -0400 Subject: [PATCH] updated newmatcher and newsink based off PR comments --- internal/sink/matcher.go | 8 ++++---- internal/sink/sink.go | 12 +++++++----- internal/sink/sinkSender.go | 5 ++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/sink/matcher.go b/internal/sink/matcher.go index 25fae7ed..fddae26e 100644 --- a/internal/sink/matcher.go +++ b/internal/sink/matcher.go @@ -47,18 +47,18 @@ type CommonWebhook struct { logger *zap.Logger } -func NewMatcher(l Listener, logger *zap.Logger) (matcher Matcher, version int, err error) { +func NewMatcher(l Listener, logger *zap.Logger) (matcher Matcher, err error) { switch v := l.(type) { case *ListenerV1: m := &MatcherV1{} m.logger = logger if err := m.update(*v); err != nil { - return nil, 0, err + return nil, err } matcher = m - return matcher, 1, nil + return matcher, nil default: - return nil, 0, fmt.Errorf("invalid listner") + return nil, fmt.Errorf("invalid listner") } } diff --git a/internal/sink/sink.go b/internal/sink/sink.go index b6c8e639..311d6ab9 100644 --- a/internal/sink/sink.go +++ b/internal/sink/sink.go @@ -39,16 +39,18 @@ type WebhookV1 struct { // clientMiddleware func(http.Client) http.Client } -func NewSink(c Config, logger *zap.Logger, id string, version int) Sink { +func NewSink(c Config, logger *zap.Logger, listener Listener) Sink { var sink Sink - if version == 1 { - v1 := &WebhookV1{ - id: id, + switch l := listener.(type) { + case *ListenerV1: + sink = &WebhookV1{ + id: l.GetId(), deliveryInterval: c.DeliveryInterval, deliveryRetries: c.DeliveryRetries, logger: logger, } - sink = v1 + default: + return nil } return sink } diff --git a/internal/sink/sinkSender.go b/internal/sink/sinkSender.go index c7899a6c..0424cce4 100644 --- a/internal/sink/sinkSender.go +++ b/internal/sink/sinkSender.go @@ -159,9 +159,8 @@ func NewSender(w *wrapper, l Listener) (s *sender, err error) { } func (s *sender) Update(l Listener) (err error) { - var version int - s.matcher, version, err = NewMatcher(l, s.logger) - s.sink = NewSink(s.config, s.logger, s.id, version) + s.matcher, err = NewMatcher(l, s.logger) + s.sink = NewSink(s.config, s.logger) s.renewalTimeGauge.Set(float64(time.Now().Unix()))