Skip to content

Commit 71bff33

Browse files
committed
add err var to ret type error
Signed-off-by: Afzal Ansari <[email protected]>
1 parent 88c1da7 commit 71bff33

File tree

11 files changed

+12
-22
lines changed

11 files changed

+12
-22
lines changed

pkg/services/alertmanager.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,11 @@ func (s alertmanagerService) Send(notification Notification, dest Destination) e
208208
return nil
209209
}
210210

211-
func (s alertmanagerService) sendOneTarget(ctx context.Context, target string, rawBody []byte) error {
211+
func (s alertmanagerService) sendOneTarget(ctx context.Context, target string, rawBody []byte) (err error) {
212212
rawURL := fmt.Sprintf("%v://%v%v", s.opts.Scheme, target, s.opts.APIPath)
213213

214214
var idleConnTimeout time.Duration
215215
if s.opts.IdleConnTimeout != "" {
216-
var err error
217216
idleConnTimeout, err = time.ParseDuration(s.opts.IdleConnTimeout)
218217
if err != nil {
219218
return fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/github.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ func NewGitHubService(opts GitHubOptions) (*gitHubService, error) {
402402

403403
var idleConnTimeout time.Duration
404404
if opts.IdleConnTimeout != "" {
405-
var err error
406405
idleConnTimeout, err = time.ParseDuration(opts.IdleConnTimeout)
407406
if err != nil {
408407
return nil, fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/googlechat.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ type webhookError struct {
107107
Status string `json:"status"`
108108
}
109109

110-
func (s googleChatService) getClient(recipient string) (*googlechatClient, error) {
110+
func (s googleChatService) getClient(recipient string) (googlechatclient *googlechatClient, err error) {
111111
webhookUrl, ok := s.opts.WebhookUrls[recipient]
112112
if !ok {
113113
return nil, fmt.Errorf("no Google chat webhook configured for recipient %s", recipient)
114114
}
115115
var idleConnTimeout time.Duration
116116
if s.opts.IdleConnTimeout != "" {
117-
var err error
118117
idleConnTimeout, err = time.ParseDuration(s.opts.IdleConnTimeout)
119118
if err != nil {
120119
return nil, fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/grafana.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type GrafanaAnnotation struct {
4141
Text string `json:"text"`
4242
}
4343

44-
func (s *grafanaService) Send(notification Notification, dest Destination) error {
44+
func (s *grafanaService) Send(notification Notification, dest Destination) (err error) {
4545
ga := GrafanaAnnotation{
4646
Time: time.Now().Unix() * 1000, // unix ts in ms
4747
IsRegion: false,
@@ -54,7 +54,6 @@ func (s *grafanaService) Send(notification Notification, dest Destination) error
5454
}
5555
var idleConnTimeout time.Duration
5656
if s.opts.IdleConnTimeout != "" {
57-
var err error
5857
idleConnTimeout, err = time.ParseDuration(s.opts.IdleConnTimeout)
5958
if err != nil {
6059
return fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/mattermost.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ func NewMattermostService(opts MattermostOptions) NotificationService {
5555
return &mattermostService{opts: opts}
5656
}
5757

58-
func (m *mattermostService) Send(notification Notification, dest Destination) error {
58+
func (m *mattermostService) Send(notification Notification, dest Destination) (err error) {
5959
var idleConnTimeout time.Duration
6060
if m.opts.IdleConnTimeout != "" {
61-
var err error
6261
idleConnTimeout, err = time.ParseDuration(m.opts.IdleConnTimeout)
6362
if err != nil {
6463
return fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/newrelic.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ type newrelicDeploymentMarkerRequest struct {
116116
Deployment NewrelicNotification `json:"deployment"`
117117
}
118118

119-
func (s newrelicService) Send(notification Notification, dest Destination) error {
119+
func (s newrelicService) Send(notification Notification, dest Destination) (err error) {
120120
if s.opts.ApiKey == "" {
121121
return ErrMissingApiKey
122122
}
@@ -140,7 +140,6 @@ func (s newrelicService) Send(notification Notification, dest Destination) error
140140

141141
var idleConnTimeout time.Duration
142142
if s.opts.IdleConnTimeout != "" {
143-
var err error
144143
idleConnTimeout, err = time.ParseDuration(s.opts.IdleConnTimeout)
145144
if err != nil {
146145
return fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/opsgenie.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,13 @@ func NewOpsgenieService(opts OpsgenieOptions) NotificationService {
250250
return &opsgenieService{opts: opts}
251251
}
252252

253-
func (s *opsgenieService) Send(notification Notification, dest Destination) error {
253+
func (s *opsgenieService) Send(notification Notification, dest Destination) (err error) {
254254
apiKey, ok := s.opts.ApiKeys[dest.Recipient]
255255
if !ok {
256256
return fmt.Errorf("no API key configured for recipient %s", dest.Recipient)
257257
}
258258
var idleConnTimeout time.Duration
259259
if s.opts.IdleConnTimeout != "" {
260-
var err error
261260
idleConnTimeout, err = time.ParseDuration(s.opts.IdleConnTimeout)
262261
if err != nil {
263262
return fmt.Errorf("failed to parse idle connection timeout: %w", err)
@@ -322,7 +321,7 @@ func (s *opsgenieService) Send(notification Notification, dest Destination) erro
322321
}
323322
}
324323

325-
_, err := alertClient.Create(context.TODO(), &alert.CreateAlertRequest{
324+
_, err = alertClient.Create(context.TODO(), &alert.CreateAlertRequest{
326325
Message: notification.Message,
327326
Description: description,
328327
Priority: priority,

pkg/services/slack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (s *slackService) Send(notification Notification, dest Destination) error {
179179
return err
180180
}
181181
return slackutil.NewThreadedClient(
182-
newSlackClient(s.opts),
182+
newSlackClient(s.opts, err),
183183
slackState,
184184
).SendMessage(
185185
context.TODO(),
@@ -196,14 +196,14 @@ func (s *slackService) GetSigningSecret() string {
196196
return s.opts.SigningSecret
197197
}
198198

199-
func newSlackClient(opts SlackOptions) *slack.Client {
199+
func newSlackClient(opts SlackOptions, err error) *slack.Client {
200200
apiURL := slack.APIURL
201201
if opts.ApiURL != "" {
202202
apiURL = opts.ApiURL
203203
}
204204
var idleConnTimeout time.Duration
205205
if opts.IdleConnTimeout != "" {
206-
idleConnTimeout, _ = time.ParseDuration(opts.IdleConnTimeout)
206+
idleConnTimeout, err = time.ParseDuration(opts.IdleConnTimeout)
207207
}
208208
transport := httputil.NewTransport(apiURL, opts.MaxIdleConns, opts.MaxIdleConnsPerHost, opts.MaxIdleConns, idleConnTimeout, opts.InsecureSkipVerify)
209209
client := &http.Client{

pkg/services/teams.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,13 @@ func NewTeamsService(opts TeamsOptions) NotificationService {
156156
return &teamsService{opts: opts}
157157
}
158158

159-
func (s teamsService) Send(notification Notification, dest Destination) error {
159+
func (s teamsService) Send(notification Notification, dest Destination) (err error) {
160160
webhookUrl, ok := s.opts.RecipientUrls[dest.Recipient]
161161
if !ok {
162162
return fmt.Errorf("no teams webhook configured for recipient %s", dest.Recipient)
163163
}
164164
var idleConnTimeout time.Duration
165165
if s.opts.IdleConnTimeout != "" {
166-
var err error
167166
idleConnTimeout, err = time.ParseDuration(s.opts.IdleConnTimeout)
168167
if err != nil {
169168
return fmt.Errorf("failed to parse idle connection timeout: %w", err)

pkg/services/webex.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ func NewWebexService(opts WebexOptions) NotificationService {
4646

4747
var validEmail = regexp.MustCompile(`^\S+@\S+\.\S+$`)
4848

49-
func (w webexService) Send(notification Notification, dest Destination) error {
49+
func (w webexService) Send(notification Notification, dest Destination) (err error) {
5050
requestURL := fmt.Sprintf("%s/v1/messages", w.opts.ApiURL)
5151

5252
var idleConnTimeout time.Duration
5353
if w.opts.IdleConnTimeout != "" {
54-
var err error
5554
idleConnTimeout, err = time.ParseDuration(w.opts.IdleConnTimeout)
5655
if err != nil {
5756
return fmt.Errorf("failed to parse idle connection timeout: %w", err)

0 commit comments

Comments
 (0)