| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 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 |