-
Notifications
You must be signed in to change notification settings - Fork 6
/
roundtrip.go
28 lines (24 loc) · 925 Bytes
/
roundtrip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) 2018, Janoš Guljaš <janos@resenje.org>
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package web
import "net/http"
// RoundTripperFunc type is an adapter to allow the use of
// ordinary functions as RoundTripper interfaces. If f is
// a function with the appropriate signature,
// RoundTripperFunc(f) is a RoundTripper that calls f.
//
// Example to set User-Agent header for every request made by Client:
//
// httpClient := &http.Client{
// Transport: RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
// r.Header.Set("User-Agent", "a clockwork orange")
// return http.DefaultTransport.RoundTrip(r)
// }),
// }
type RoundTripperFunc func(*http.Request) (*http.Response, error)
// RoundTrip calls f(r).
func (f RoundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
return f(r)
}