Skip to content

Commit 0cc1347

Browse files
committed
refactor: simplify HTTP client initialization by using TransportOptions directly
Signed-off-by: Afzal Ansari <[email protected]>
1 parent 22ebd3c commit 0cc1347

File tree

11 files changed

+11
-78
lines changed

11 files changed

+11
-78
lines changed

pkg/services/alertmanager.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,7 @@ func (s alertmanagerService) Send(notification Notification, dest Destination) e
208208
func (s alertmanagerService) sendOneTarget(ctx context.Context, target string, rawBody []byte) (err error) {
209209
rawURL := fmt.Sprintf("%v://%v%v", s.opts.Scheme, target, s.opts.APIPath)
210210

211-
tp := httputil.TransportOptions{
212-
MaxIdleConns: s.opts.MaxIdleConns,
213-
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
214-
MaxConnsPerHost: s.opts.MaxConnsPerHost,
215-
IdleConnTimeout: s.opts.IdleConnTimeout,
216-
}
217-
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, rawURL, "alertmanager")
211+
client, err := httputil.NewServiceHTTPClient(s.opts.TransportOptions, s.opts.InsecureSkipVerify, rawURL, "alertmanager")
218212
if err != nil {
219213
return err
220214
}

pkg/services/github.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,7 @@ func NewGitHubService(opts GitHubOptions) (*gitHubService, error) {
396396
return nil, err
397397
}
398398

399-
tp := httputil.TransportOptions{
400-
MaxIdleConns: opts.MaxIdleConns,
401-
MaxIdleConnsPerHost: opts.MaxIdleConnsPerHost,
402-
MaxConnsPerHost: opts.MaxConnsPerHost,
403-
IdleConnTimeout: opts.IdleConnTimeout,
404-
}
405-
406-
client, err := httputil.NewServiceHTTPClient(tp, opts.InsecureSkipVerify, url, "github")
399+
client, err := httputil.NewServiceHTTPClient(opts.TransportOptions, opts.InsecureSkipVerify, url, "github")
407400
if err != nil {
408401
return nil, err
409402
}

pkg/services/googlechat.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ func (s googleChatService) getClient(recipient string) (googlechatclient *google
108108
return nil, fmt.Errorf("no Google chat webhook configured for recipient %s", recipient)
109109
}
110110

111-
tp := httputil.TransportOptions{
112-
MaxIdleConns: s.opts.MaxIdleConns,
113-
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
114-
MaxConnsPerHost: s.opts.MaxConnsPerHost,
115-
IdleConnTimeout: s.opts.IdleConnTimeout,
116-
}
117-
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, webhookUrl, "googlechat")
111+
client, err := httputil.NewServiceHTTPClient(s.opts.TransportOptions, s.opts.InsecureSkipVerify, webhookUrl, "googlechat")
118112
if err != nil {
119113
return nil, err
120114
}

pkg/services/grafana.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ func (s *grafanaService) Send(notification Notification, dest Destination) (err
5050
log.Warnf("Message is an empty string or not provided in the notifications template")
5151
}
5252

53-
tp := httputil.TransportOptions{
54-
MaxIdleConns: s.opts.MaxIdleConns,
55-
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
56-
MaxConnsPerHost: s.opts.MaxConnsPerHost,
57-
IdleConnTimeout: s.opts.IdleConnTimeout,
58-
}
59-
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "grafana")
53+
client, err := httputil.NewServiceHTTPClient(s.opts.TransportOptions, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "grafana")
6054
if err != nil {
6155
return err
6256
}

pkg/services/mattermost.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ func NewMattermostService(opts MattermostOptions) NotificationService {
5050
}
5151

5252
func (m *mattermostService) Send(notification Notification, dest Destination) (err error) {
53-
tp := httputil.TransportOptions{
54-
MaxIdleConns: m.opts.MaxIdleConns,
55-
MaxIdleConnsPerHost: m.opts.MaxIdleConnsPerHost,
56-
MaxConnsPerHost: m.opts.MaxConnsPerHost,
57-
IdleConnTimeout: m.opts.IdleConnTimeout,
58-
}
59-
client, err := httputil.NewServiceHTTPClient(tp, m.opts.InsecureSkipVerify, m.opts.ApiURL, "mattermost")
53+
client, err := httputil.NewServiceHTTPClient(m.opts.TransportOptions, m.opts.InsecureSkipVerify, m.opts.ApiURL, "mattermost")
6054
if err != nil {
6155
return err
6256
}

pkg/services/newrelic.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,7 @@ func (s newrelicService) Send(notification Notification, dest Destination) (err
134134
},
135135
}
136136

137-
tp := httputil.TransportOptions{
138-
MaxIdleConns: s.opts.MaxIdleConns,
139-
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
140-
MaxConnsPerHost: s.opts.MaxConnsPerHost,
141-
IdleConnTimeout: s.opts.IdleConnTimeout,
142-
}
143-
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, s.opts.ApiURL, "newrelic")
137+
client, err := httputil.NewServiceHTTPClient(s.opts.TransportOptions, s.opts.InsecureSkipVerify, s.opts.ApiURL, "newrelic")
144138
if err != nil {
145139
return err
146140
}

pkg/services/opsgenie.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,7 @@ func (s *opsgenieService) Send(notification Notification, dest Destination) (err
250250
return fmt.Errorf("no API key configured for recipient %s", dest.Recipient)
251251
}
252252

253-
tp := httputil.TransportOptions{
254-
MaxIdleConns: s.opts.MaxIdleConns,
255-
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
256-
MaxConnsPerHost: s.opts.MaxConnsPerHost,
257-
IdleConnTimeout: s.opts.IdleConnTimeout,
258-
}
259-
opsclient, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "opsgenie")
253+
opsclient, err := httputil.NewServiceHTTPClient(s.opts.TransportOptions, s.opts.InsecureSkipVerify, s.opts.ApiUrl, "opsgenie")
260254
if err != nil {
261255
return err
262256
}

pkg/services/slack.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,7 @@ func newSlackClient(opts SlackOptions) (slackclient *slack.Client, err error) {
202202
apiURL = opts.ApiURL
203203
}
204204

205-
tp := httputil.TransportOptions{
206-
MaxIdleConns: opts.MaxIdleConns,
207-
MaxIdleConnsPerHost: opts.MaxIdleConnsPerHost,
208-
MaxConnsPerHost: opts.MaxConnsPerHost,
209-
IdleConnTimeout: opts.IdleConnTimeout,
210-
}
211-
client, err := httputil.NewServiceHTTPClient(tp, opts.InsecureSkipVerify, apiURL, "slack")
205+
client, err := httputil.NewServiceHTTPClient(opts.TransportOptions, opts.InsecureSkipVerify, apiURL, "slack")
212206
if err != nil {
213207
return nil, err
214208
}

pkg/services/teams.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ func (s teamsService) Send(notification Notification, dest Destination) (err err
155155
return fmt.Errorf("no teams webhook configured for recipient %s", dest.Recipient)
156156
}
157157

158-
tp := httputil.TransportOptions{
159-
MaxIdleConns: s.opts.MaxIdleConns,
160-
MaxIdleConnsPerHost: s.opts.MaxIdleConnsPerHost,
161-
MaxConnsPerHost: s.opts.MaxConnsPerHost,
162-
IdleConnTimeout: s.opts.IdleConnTimeout,
163-
}
164-
client, err := httputil.NewServiceHTTPClient(tp, s.opts.InsecureSkipVerify, webhookUrl, "teams")
158+
client, err := httputil.NewServiceHTTPClient(s.opts.TransportOptions, s.opts.InsecureSkipVerify, webhookUrl, "teams")
165159
if err != nil {
166160
return err
167161
}

pkg/services/webex.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ var validEmail = regexp.MustCompile(`^\S+@\S+\.\S+$`)
4343
func (w webexService) Send(notification Notification, dest Destination) (err error) {
4444
requestURL := fmt.Sprintf("%s/v1/messages", w.opts.ApiURL)
4545

46-
tp := httputil.TransportOptions{
47-
MaxIdleConns: w.opts.MaxIdleConns,
48-
MaxIdleConnsPerHost: w.opts.MaxIdleConnsPerHost,
49-
MaxConnsPerHost: w.opts.MaxConnsPerHost,
50-
IdleConnTimeout: w.opts.IdleConnTimeout,
51-
}
52-
client, err := httputil.NewServiceHTTPClient(tp, w.opts.InsecureSkipVerify, requestURL, "webex")
46+
client, err := httputil.NewServiceHTTPClient(w.opts.TransportOptions, w.opts.InsecureSkipVerify, requestURL, "webex")
5347
if err != nil {
5448
return err
5549
}

0 commit comments

Comments
 (0)