-
Notifications
You must be signed in to change notification settings - Fork 12
/
proxy_no_error.go
44 lines (37 loc) · 1.14 KB
/
proxy_no_error.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
// +build !go1.11
package gimlet
import (
"net/http/httputil"
"github.com/mongodb/grip"
"github.com/mongodb/grip/level"
"github.com/mongodb/grip/message"
)
// Proxy adds a simple reverse proxy handler to the specified route,
// based on the options described in the ProxyOption structure.
// In most cases you'll want to specify a route matching pattern
// that captures all routes that begin with a specific prefix.
func (r *APIRoute) Proxy(opts ProxyOptions) *APIRoute {
if err := opts.Validate(); err != nil {
grip.Alert(message.WrapError(err, message.Fields{
"message": "invalid proxy options",
"route": r.route,
"version": r.version,
"existing_handler": r.handler != nil,
}))
return r
}
if opts.ErrorHandler != nil {
grip.Alert(message.Fields{
"message": "custom error handler ignored in < go1.11",
"route": r.route,
"version": r.version,
"existing_handler": r.handler != nil,
})
}
r.handler = (&httputil.ReverseProxy{
Transport: opts.Transport,
ErrorLog: grip.MakeStandardLogger(level.Warning),
Director: opts.director,
}).ServeHTTP
return r
}