From fe5542845e869d6880f8c1cdeb53adbd267555a7 Mon Sep 17 00:00:00 2001 From: Sajitha Date: Tue, 27 Oct 2020 21:19:28 +0530 Subject: [PATCH] Fix golint warnings for publisher package (#1822) Co-authored-by: Shajitha Mohammed --- pkg/publisher/publisher.go | 4 +++- pkg/publisher/webhookPublisher.go | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/publisher/publisher.go b/pkg/publisher/publisher.go index 7c2a77c7..918963a8 100644 --- a/pkg/publisher/publisher.go +++ b/pkg/publisher/publisher.go @@ -17,8 +17,10 @@ limitations under the License. package publisher type ( + // Publisher interface wraps the Publish method that publishes an request + // with given "body" and "headers" to given "target" Publisher interface { - // Publish an request to a "target". Target's meaning depends on the + // Publish an request to a "target". Target's meaning depends on the // publisher: it's a URL in the case of a webhook publisher, or a queue // name in a queue-based publisher such as NATS. Publish(body string, headers map[string]string, target string) diff --git a/pkg/publisher/webhookPublisher.go b/pkg/publisher/webhookPublisher.go index c8258db2..505901d7 100644 --- a/pkg/publisher/webhookPublisher.go +++ b/pkg/publisher/webhookPublisher.go @@ -27,7 +27,7 @@ import ( ) type ( - // A webhook publisher for a single URL. Satisifies the Publisher interface. + // WebhookPublisher for a single URL. Satisfies the Publisher interface. WebhookPublisher struct { logger *zap.Logger @@ -36,7 +36,7 @@ type ( maxRetries int retryDelay time.Duration - baseUrl string + baseURL string } publishRequest struct { body string @@ -47,10 +47,11 @@ type ( } ) -func MakeWebhookPublisher(logger *zap.Logger, baseUrl string) *WebhookPublisher { +// MakeWebhookPublisher creates a WebhookPublisher object for the given baseURL +func MakeWebhookPublisher(logger *zap.Logger, baseURL string) *WebhookPublisher { p := &WebhookPublisher{ logger: logger.Named("webhook_publisher"), - baseUrl: baseUrl, + baseURL: baseURL, requestChannel: make(chan *publishRequest, 32), // buffered channel // TODO make this configurable maxRetries: 10, @@ -60,6 +61,7 @@ func MakeWebhookPublisher(logger *zap.Logger, baseUrl string) *WebhookPublisher return p } +// Publish sends a request to the target with payload having given body and headers func (p *WebhookPublisher) Publish(body string, headers map[string]string, target string) { // serializing the request gives user a guarantee that the request is sent in sequence order p.requestChannel <- &publishRequest{ @@ -74,12 +76,12 @@ func (p *WebhookPublisher) Publish(body string, headers map[string]string, targe func (p *WebhookPublisher) svc() { for { r := <-p.requestChannel - p.makeHttpRequest(r) + p.makeHTTPRequest(r) } } -func (p *WebhookPublisher) makeHttpRequest(r *publishRequest) { - url := p.baseUrl + "/" + strings.TrimPrefix(r.target, "/") +func (p *WebhookPublisher) makeHTTPRequest(r *publishRequest) { + url := p.baseURL + "/" + strings.TrimPrefix(r.target, "/") msg := "making HTTP request" level := zap.ErrorLevel