client.decorateTransportWithUserAgentDecorator   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
package client
2
3
import (
4
	"errors"
5
	"net/http"
6
)
7
8
func decorateTransportWithUserAgentDecorator(decorated http.RoundTripper, userAgent string) (*userAgentTransportDecorator, error) {
9
	if decorated == nil {
10
		return nil, errors.New("decorated round tripper is nil")
11
	}
12
13
	return &userAgentTransportDecorator{decorated: decorated, userAgent: userAgent}, nil
14
}
15
16
type userAgentTransportDecorator struct {
17
	decorated http.RoundTripper
18
	userAgent string
19
}
20
21
func (u *userAgentTransportDecorator) RoundTrip(r *http.Request) (*http.Response, error) {
22
	r.Header.Set("User-Agent", u.userAgent)
23
24
	return u.decorated.RoundTrip(r)
25
}
26