interface.go 850 B

123456789101112131415161718192021222324252627282930313233343536
  1. package loadmodule
  2. import "net/url"
  3. type ProxyLoadType int
  4. const (
  5. RandomProxyModule ProxyLoadType = iota //随机
  6. RoundRobinProxyModule //轮询
  7. WeightRoundRobinProxyModule //权重
  8. //ConsistentHashProxy //哈希
  9. )
  10. type ProxyLoadModule interface {
  11. Add(string) error
  12. Get() *url.URL
  13. Len() int
  14. Update() //动态添加
  15. }
  16. func LoadProxyLoadFactory(value int) ProxyLoadModule {
  17. loadType := ProxyLoadType(value)
  18. switch loadType {
  19. case RandomProxyModule: //随机
  20. return &RandomProxy{}
  21. case RoundRobinProxyModule: //轮询
  22. return &RoundRobinProxy{}
  23. case WeightRoundRobinProxyModule: //权重
  24. return &WeightRoundRobinProxy{}
  25. //case ConsistentHashProxy: //哈希
  26. // return NewConsistentHashBanlance(10, nil)
  27. default:
  28. return &RandomProxy{}
  29. }
  30. }