File tree Expand file tree Collapse file tree 3 files changed +25
-10
lines changed
Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ func BodyDump(handler BodyDumpHandler) echo.MiddlewareFunc {
5050}
5151
5252// BodyDumpWithConfig returns a BodyDump middleware with config.
53- // See: `BodyConfig ()`.
53+ // See: `BodyDump ()`.
5454func BodyDumpWithConfig (config BodyDumpConfig ) echo.MiddlewareFunc {
5555 // Defaults
5656 if config .Handler == nil {
Original file line number Diff line number Diff line change @@ -53,6 +53,13 @@ type (
5353 }
5454)
5555
56+ var (
57+ // DefaultProxyConfig is the default Proxy middleware config.
58+ DefaultProxyConfig = ProxyConfig {
59+ Skipper : DefaultSkipper ,
60+ }
61+ )
62+
5663func proxyHTTP (t * ProxyTarget ) http.Handler {
5764 return httputil .NewSingleHostReverseProxy (t .URL )
5865}
@@ -113,8 +120,18 @@ func (r *RoundRobinBalancer) Next() *ProxyTarget {
113120 return t
114121}
115122
116- // Proxy returns an HTTP/WebSocket reverse proxy middleware.
117- func Proxy (config ProxyConfig ) echo.MiddlewareFunc {
123+ // Proxy returns a Proxy middleware.
124+ //
125+ // Proxy middleware forwards a request to upstream server using a configured load balancing technique.
126+ func Proxy (balancer ProxyBalancer ) echo.MiddlewareFunc {
127+ c := DefaultProxyConfig
128+ c .Balancer = balancer
129+ return ProxyWithConfig (c )
130+ }
131+
132+ // ProxyWithConfig returns a Proxy middleware with config.
133+ // See: `Proxy()`
134+ func ProxyWithConfig (config ProxyConfig ) echo.MiddlewareFunc {
118135 // Defaults
119136 if config .Skipper == nil {
120137 config .Skipper = DefaultLoggerConfig .Skipper
Original file line number Diff line number Diff line change @@ -55,15 +55,13 @@ func TestProxy(t *testing.T) {
5555 URL : url2 ,
5656 },
5757 }
58- config := ProxyConfig {
59- Balancer : & RandomBalancer {
60- Targets : targets ,
61- },
58+ rb := & RandomBalancer {
59+ Targets : targets ,
6260 }
6361
6462 // Random
6563 e := echo .New ()
66- e .Use (Proxy (config ))
64+ e .Use (Proxy (rb ))
6765 req := httptest .NewRequest (echo .GET , "/" , nil )
6866 rec := newCloseNotifyRecorder ()
6967 e .ServeHTTP (rec , req )
@@ -77,11 +75,11 @@ func TestProxy(t *testing.T) {
7775 })
7876
7977 // Round-robin
80- config . Balancer = & RoundRobinBalancer {
78+ rrb : = & RoundRobinBalancer {
8179 Targets : targets ,
8280 }
8381 e = echo .New ()
84- e .Use (Proxy (config ))
82+ e .Use (Proxy (rrb ))
8583 rec = newCloseNotifyRecorder ()
8684 e .ServeHTTP (rec , req )
8785 body = rec .Body .String ()
You can’t perform that action at this time.
0 commit comments