originPicker.go 618 B

1234567891011121314151617181920212223242526
  1. package loadbalance
  2. import (
  3. "errors"
  4. "fmt"
  5. "net/http"
  6. )
  7. /*
  8. Origin Picker
  9. This script contains the code to pick the best origin
  10. by this request.
  11. */
  12. // GetRequestUpstreamTarget return the upstream target where this
  13. // request should be routed
  14. func (m *RouteManager) GetRequestUpstreamTarget(r *http.Request, origins []*Upstream) (*Upstream, error) {
  15. if len(origins) == 0 {
  16. return nil, errors.New("no upstream is defined for this host")
  17. }
  18. //TODO: Add upstream picking algorithm here
  19. fmt.Println("DEBUG: Picking origin " + origins[0].OriginIpOrDomain)
  20. return origins[0], nil
  21. }