Proxy Middleware

Proxy provides an HTTP/WebSocket reverse proxy middleware. It forwards a requestto upstream server using a configured load balancing technique.

Usage

  1. url1, err := url.Parse("http://localhost:8081")
  2. if err != nil {
  3. e.Logger.Fatal(err)
  4. }
  5. url2, err := url.Parse("http://localhost:8082")
  6. if err != nil {
  7. e.Logger.Fatal(err)
  8. }
  9. e.Use(middleware.Proxy(middleware.NewRoundRobinBalancer([]*middleware.ProxyTarget{
  10. {
  11. URL: url1,
  12. },
  13. {
  14. URL: url2,
  15. },
  16. })))

Custom Configuration

Usage

  1. e := echo.New()
  2. e.Use(middleware.ProxyWithConfig(middleware.ProxyConfig{}))

Configuration

  1. // ProxyConfig defines the config for Proxy middleware.
  2. ProxyConfig struct {
  3. // Skipper defines a function to skip middleware.
  4. Skipper Skipper
  5. // Balancer defines a load balancing technique.
  6. // Required.
  7. // Possible values:
  8. // - RandomBalancer
  9. // - RoundRobinBalancer
  10. Balancer ProxyBalancer
  11. }

Default Configuration

NameValue
SkipperDefaultSkipper

Example