originPicker.go 540 B

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