router.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package routing
  2. import (
  3. "v2ray.com/core/common"
  4. "v2ray.com/core/features"
  5. )
  6. // Router is a feature to choose an outbound tag for the given request.
  7. //
  8. // v2ray:api:beta
  9. type Router interface {
  10. features.Feature
  11. // PickRoute returns a tag of an OutboundHandler based on the given context.
  12. PickRoute(ctx Context) (string, error)
  13. }
  14. // RouterType return the type of Router interface. Can be used to implement common.HasType.
  15. //
  16. // v2ray:api:stable
  17. func RouterType() interface{} {
  18. return (*Router)(nil)
  19. }
  20. // DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions.
  21. type DefaultRouter struct{}
  22. // Type implements common.HasType.
  23. func (DefaultRouter) Type() interface{} {
  24. return RouterType()
  25. }
  26. // PickRoute implements Router.
  27. func (DefaultRouter) PickRoute(ctx Context) (string, error) {
  28. return "", common.ErrNoClue
  29. }
  30. // Start implements common.Runnable.
  31. func (DefaultRouter) Start() error {
  32. return nil
  33. }
  34. // Close implements common.Closable.
  35. func (DefaultRouter) Close() error {
  36. return nil
  37. }