@@ -113,7 +113,7 @@ func NewWebhookProvider(u string) (*WebhookProvider, error) {
113
113
}
114
114
115
115
// negotiate API information
116
- req , err := http .NewRequest ("GET" , u , nil )
116
+ req , err := http .NewRequest (http . MethodGet , u , nil )
117
117
if err != nil {
118
118
return nil , err
119
119
}
@@ -128,8 +128,8 @@ func NewWebhookProvider(u string) (*WebhookProvider, error) {
128
128
return err
129
129
}
130
130
// we currently only use 200 as success, but considering okay all 2XX for future usage
131
- if resp .StatusCode >= 300 && resp .StatusCode < 500 {
132
- return backoff .Permanent (fmt .Errorf ("status code < 500" ))
131
+ if resp .StatusCode >= http . StatusMultipleChoices && resp .StatusCode < http . StatusInternalServerError {
132
+ return backoff .Permanent (fmt .Errorf ("status code < %d" , http . StatusInternalServerError ))
133
133
}
134
134
return nil
135
135
}, backoff .WithMaxRetries (backoff .NewExponentialBackOff (), maxRetries ))
@@ -164,7 +164,7 @@ func (p WebhookProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err
164
164
recordsRequestsGauge .Gauge .Inc ()
165
165
u := p .remoteServerURL .JoinPath ("records" ).String ()
166
166
167
- req , err := http .NewRequest ("GET" , u , nil )
167
+ req , err := http .NewRequest (http . MethodGet , u , nil )
168
168
if err != nil {
169
169
recordsErrorsGauge .Gauge .Inc ()
170
170
log .Debugf ("Failed to create request: %s" , err .Error ())
@@ -189,7 +189,7 @@ func (p WebhookProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err
189
189
return nil , err
190
190
}
191
191
192
- endpoints := []* endpoint.Endpoint {}
192
+ var endpoints []* endpoint.Endpoint
193
193
if err := json .NewDecoder (resp .Body ).Decode (& endpoints ); err != nil {
194
194
recordsErrorsGauge .Gauge .Inc ()
195
195
log .Debugf ("Failed to decode response body: %s" , err .Error ())
@@ -201,7 +201,7 @@ func (p WebhookProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err
201
201
// ApplyChanges will make a POST to remoteServerURL/records with the changes
202
202
func (p WebhookProvider ) ApplyChanges (ctx context.Context , changes * plan.Changes ) error {
203
203
applyChangesRequestsGauge .Gauge .Inc ()
204
- u := p .remoteServerURL .JoinPath ("records" ).String ()
204
+ u := p .remoteServerURL .JoinPath (webhookapi . UrlRecords ).String ()
205
205
206
206
b := new (bytes.Buffer )
207
207
if err := json .NewEncoder (b ).Encode (changes ); err != nil {
@@ -210,7 +210,7 @@ func (p WebhookProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
210
210
return err
211
211
}
212
212
213
- req , err := http .NewRequest ("POST" , u , b )
213
+ req , err := http .NewRequest (http . MethodPost , u , b )
214
214
if err != nil {
215
215
applyChangesErrorsGauge .Gauge .Inc ()
216
216
log .Debugf ("Failed to create request: %s" , err .Error ())
@@ -225,6 +225,7 @@ func (p WebhookProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
225
225
log .Debugf ("Failed to perform request: %s" , err .Error ())
226
226
return err
227
227
}
228
+
228
229
defer resp .Body .Close ()
229
230
230
231
if resp .StatusCode != http .StatusNoContent {
@@ -240,12 +241,12 @@ func (p WebhookProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
240
241
}
241
242
242
243
// AdjustEndpoints will call the provider doing a POST on `/adjustendpoints` which will return a list of modified endpoints
243
- // based on a provider specific requirement.
244
+ // based on a provider- specific requirement.
244
245
// This method returns an empty slice in case there is a technical error on the provider's side so that no endpoints will be considered.
245
246
func (p WebhookProvider ) AdjustEndpoints (e []* endpoint.Endpoint ) ([]* endpoint.Endpoint , error ) {
246
247
adjustEndpointsRequestsGauge .Gauge .Inc ()
247
- endpoints := []* endpoint.Endpoint {}
248
- u , err := url .JoinPath (p .remoteServerURL .String (), "adjustendpoints" )
248
+ var endpoints []* endpoint.Endpoint
249
+ u , err := url .JoinPath (p .remoteServerURL .String (), webhookapi . UrlAdjustEndpoints )
249
250
if err != nil {
250
251
adjustEndpointsErrorsGauge .Gauge .Inc ()
251
252
log .Debugf ("Failed to join path, %s" , err )
@@ -259,7 +260,7 @@ func (p WebhookProvider) AdjustEndpoints(e []*endpoint.Endpoint) ([]*endpoint.En
259
260
return nil , err
260
261
}
261
262
262
- req , err := http .NewRequest ("POST" , u , b )
263
+ req , err := http .NewRequest (http . MethodPost , u , b )
263
264
if err != nil {
264
265
adjustEndpointsErrorsGauge .Gauge .Inc ()
265
266
log .Debugf ("Failed to create new HTTP request, %s" , err )
0 commit comments