fix block routes

This commit is contained in:
Yuzuki999
2022-12-21 02:49:23 +08:00
parent bb430dbb8d
commit d98ec9f61c
2 changed files with 13 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/goccy/go-json"
"regexp"
"strconv"
"strings"
)
type NodeInfo struct {
@@ -60,12 +61,13 @@ func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
nodeInfo.NodeId = c.NodeId
nodeInfo.NodeType = c.NodeType
for i := range nodeInfo.Routes { // parse rules from routes
r := &nodeInfo.Routes[i]
if r.Action == "block" {
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
ID: r.Id,
Pattern: regexp.MustCompile(r.Match),
})
if nodeInfo.Routes[i].Action == "block" {
for _, v := range strings.Split(nodeInfo.Routes[i].Match, ",") {
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
ID: nodeInfo.Routes[i].Id,
Pattern: regexp.MustCompile(v),
})
}
}
}
nodeInfo.Routes = nil