add path option for hop
This commit is contained in:
21
hop/hop.go
21
hop/hop.go
@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -179,6 +180,26 @@ func (p *chainHop) Select(ctx context.Context, opts ...hop.SelectOption) *chain.
|
||||
}
|
||||
}
|
||||
|
||||
// filter by path
|
||||
if path := options.Path; path != "" {
|
||||
p.options.logger.Debugf("filter by path: %s", path)
|
||||
sort.SliceStable(filters, func(i, j int) bool {
|
||||
return len(filters[i].Options().Path) > len(filters[j].Options().Path)
|
||||
})
|
||||
var nodes []*chain.Node
|
||||
for _, node := range filters {
|
||||
if node.Options().Path == "" {
|
||||
nodes = append(nodes, node)
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(path, node.Options().Path) {
|
||||
nodes = append(nodes, node)
|
||||
break
|
||||
}
|
||||
}
|
||||
filters = nodes
|
||||
}
|
||||
|
||||
var nodes []*chain.Node
|
||||
for _, node := range filters {
|
||||
if node == nil {
|
||||
|
@ -67,6 +67,7 @@ func (p *grpcPlugin) Select(ctx context.Context, opts ...hop.SelectOption) *chai
|
||||
Network: options.Network,
|
||||
Addr: options.Addr,
|
||||
Host: options.Host,
|
||||
Path: options.Path,
|
||||
Client: string(auth_util.IDFromContext(ctx)),
|
||||
})
|
||||
if err != nil {
|
||||
@ -103,6 +104,7 @@ type httpPluginRequest struct {
|
||||
Network string `json:"network"`
|
||||
Addr string `json:"addr"`
|
||||
Host string `json:"host"`
|
||||
Path string `json:"path"`
|
||||
Client string `json:"client"`
|
||||
}
|
||||
|
||||
@ -151,6 +153,7 @@ func (p *httpPlugin) Select(ctx context.Context, opts ...hop.SelectOption) *chai
|
||||
Network: options.Network,
|
||||
Addr: options.Addr,
|
||||
Host: options.Host,
|
||||
Path: options.Path,
|
||||
Client: string(auth_util.IDFromContext(ctx)),
|
||||
}
|
||||
v, err := json.Marshal(&rb)
|
||||
|
Reference in New Issue
Block a user