github.com/xraypb/Xray-core@v1.8.1/features/routing/router.go (about) 1 package routing 2 3 import ( 4 "github.com/xraypb/Xray-core/common" 5 "github.com/xraypb/Xray-core/features" 6 ) 7 8 // Router is a feature to choose an outbound tag for the given request. 9 // 10 // xray:api:stable 11 type Router interface { 12 features.Feature 13 14 // PickRoute returns a route decision based on the given routing context. 15 PickRoute(ctx Context) (Route, error) 16 } 17 18 // Route is the routing result of Router feature. 19 // 20 // xray:api:stable 21 type Route interface { 22 // A Route is also a routing context. 23 Context 24 25 // GetOutboundGroupTags returns the detoured outbound group tags in sequence before a final outbound is chosen. 26 GetOutboundGroupTags() []string 27 28 // GetOutboundTag returns the tag of the outbound the connection was dispatched to. 29 GetOutboundTag() string 30 } 31 32 // RouterType return the type of Router interface. Can be used to implement common.HasType. 33 // 34 // xray:api:stable 35 func RouterType() interface{} { 36 return (*Router)(nil) 37 } 38 39 // DefaultRouter is an implementation of Router, which always returns ErrNoClue for routing decisions. 40 type DefaultRouter struct{} 41 42 // Type implements common.HasType. 43 func (DefaultRouter) Type() interface{} { 44 return RouterType() 45 } 46 47 // PickRoute implements Router. 48 func (DefaultRouter) PickRoute(ctx Context) (Route, error) { 49 return nil, common.ErrNoClue 50 } 51 52 // Start implements common.Runnable. 53 func (DefaultRouter) Start() error { 54 return nil 55 } 56 57 // Close implements common.Closable. 58 func (DefaultRouter) Close() error { 59 return nil 60 }