-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
37 lines (31 loc) · 789 Bytes
/
Copy pathoptions.go
File metadata and controls
37 lines (31 loc) · 789 Bytes
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
package rhttp
import "net/http"
// Option configures a Client.
type Option func(*config)
type config struct {
transport http.RoundTripper
middleware []Middleware
}
func defaultConfig() *config {
return &config{
transport: DefaultTransport(),
}
}
// WithTransport sets a custom http.RoundTripper.
//
// A nil transport is discarded and DefaultTransport is kept, so no protection is
// lost. Unlike the middleware constructors, this case is not reported through
// OnInvalidConfig.
func WithTransport(rt http.RoundTripper) Option {
return func(c *config) {
if rt != nil {
c.transport = rt
}
}
}
// WithMiddleware appends middleware to the chain.
func WithMiddleware(mw ...Middleware) Option {
return func(c *config) {
c.middleware = append(c.middleware, mw...)
}
}