mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-27 08:11:48 +00:00
API: Add ListRule() for routing (#5569)
https://github.com/XTLS/Xray-core/pull/5569#issuecomment-3766310407
This commit is contained in:
@@ -60,6 +60,7 @@ func (s *routingServer) AddRule(ctx context.Context, request *AddRuleRequest) (*
|
||||
return nil, errors.New("unsupported router implementation")
|
||||
|
||||
}
|
||||
|
||||
func (s *routingServer) RemoveRule(ctx context.Context, request *RemoveRuleRequest) (*RemoveRuleResponse, error) {
|
||||
if bo, ok := s.router.(routing.Router); ok {
|
||||
return &RemoveRuleResponse{}, bo.RemoveRule(request.RuleTag)
|
||||
@@ -67,6 +68,20 @@ func (s *routingServer) RemoveRule(ctx context.Context, request *RemoveRuleReque
|
||||
return nil, errors.New("unsupported router implementation")
|
||||
}
|
||||
|
||||
func (s *routingServer) ListRule(ctx context.Context, request *ListRuleRequest) (*ListRuleResponse, error) {
|
||||
if bo, ok := s.router.(routing.Router); ok {
|
||||
response := &ListRuleResponse{}
|
||||
for _, v := range bo.ListRule() {
|
||||
response.Rules = append(response.Rules, &ListRuleItem{
|
||||
Tag: v.GetOutboundTag(),
|
||||
RuleTag: v.GetRuleTag(),
|
||||
})
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
return nil, errors.New("unsupported router implementation")
|
||||
}
|
||||
|
||||
// NewRoutingServer creates a statistics service with statistics manager.
|
||||
func NewRoutingServer(router routing.Router, routingStats stats.Channel) RoutingServiceServer {
|
||||
return &routingServer{
|
||||
|
||||
Reference in New Issue
Block a user