Proxy

Proxy provides an HTTP/WebSocket reverse proxy middleware. It forwards a request
to 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.RoundRobinBalancer{
  10. Targets: []*middleware.ProxyTarget{
  11. &middleware.ProxyTarget{
  12. URL: url1,
  13. },
  14. &middleware.ProxyTarget{
  15. URL: url2,
  16. },
  17. },
  18. }))

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

Name Value
Skipper DefaultSkipper

Example