From 06cc8e7102b2cd964690c20020c37e90cef93287 Mon Sep 17 00:00:00 2001 From: Mustafa YILDIRIM Date: Tue, 23 Apr 2024 15:21:00 -0700 Subject: [PATCH] add extensible header configuration --- lib/novu.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/novu.go b/lib/novu.go index 5f5925c..ea22265 100644 --- a/lib/novu.go +++ b/lib/novu.go @@ -29,9 +29,10 @@ type RetryConfigType struct { } type Config struct { - BackendURL *url.URL - HttpClient *http.Client - RetryConfig *RetryConfigType + BackendURL *url.URL + HttpClient *http.Client + HttpClientHeaders map[string]string + RetryConfig *RetryConfigType } type APIClient struct { @@ -51,7 +52,7 @@ type APIClient struct { IntegrationsApi *IntegrationService InboundParserApi *InboundParserService LayoutApi *LayoutService - TenantApi *TenantService + TenantApi *TenantService } type service struct { @@ -120,6 +121,13 @@ func (c APIClient) sendRequest(req *http.Request, resp interface{}) (*http.Respo req.Header.Set("Authorization", fmt.Sprintf("ApiKey %s", c.apiKey)) req.Header.Set("Idempotency-Key", uuid.New().String()) + headers := c.config.HttpClientHeaders + if headers != nil { + for header, value := range headers { + req.Header.Set(header, value) + } + } + res, err := c.config.HttpClient.Do(req) if err != nil { return res, errors.Wrap(err, "failed to execute request")