/
transport.go
50 lines (39 loc) · 1000 Bytes
/
transport.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package transport
import (
"net/http"
"github.com/konradasb/github_exporter/cache"
"github.com/konradasb/github_exporter/validators"
"go.uber.org/ratelimit"
)
type transport struct {
Next http.RoundTripper
}
// NewTransport initializes Transport instances
func NewTransport(rt http.RoundTripper) *transport {
if rt == nil {
rt = http.DefaultTransport
}
t := &transport{
Next: rt,
}
return t
}
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
return t.Next.RoundTrip(req)
}
func (t *transport) WithRevalidation(v validators.Validator) *transport {
t.Next = NewRevalidationTransport(t.Next, v)
return t
}
func (t *transport) WithThrottle(rtl ratelimit.Limiter) *transport {
t.Next = NewThrottleTransport(t.Next, rtl)
return t
}
func (t *transport) WithCache(cache cache.Cache) *transport {
t.Next = NewCacheTransport(t.Next, cache)
return t
}
func (t *transport) WithRatelimit() *transport {
t.Next = NewRatelimitTransport(t.Next)
return t
}