Passed
Pull Request — master (#41)
by Stefano
02:42
created

pkg/scan/client/headers.go   A

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A client.*headersTransportDecorator.RoundTrip 0 6 2
A client.decorateTransportWithHeadersDecorator 0 10 3
1
package client
2
3
import (
4
	"errors"
5
	"net/http"
6
)
7
8
func decorateTransportWithHeadersDecorator(decorated http.RoundTripper, headers map[string]string) (*headersTransportDecorator, error) {
9
	if decorated == nil {
10
		return nil, errors.New("decorated round tripper is nil")
11
	}
12
13
	if headers == nil {
14
		return nil, errors.New("headers is nil")
15
	}
16
17
	return &headersTransportDecorator{decorated: decorated, headers: headers}, nil
18
}
19
20
type headersTransportDecorator struct {
21
	decorated http.RoundTripper
22
	headers   map[string]string
23
}
24
25
func (h *headersTransportDecorator) RoundTrip(r *http.Request) (*http.Response, error) {
26
	for key, value := range h.headers {
27
		r.Header.Set(key, value)
28
	}
29
30
	return h.decorated.RoundTrip(r)
31
}
32