-
Notifications
You must be signed in to change notification settings - Fork 0
/
hop.go
48 lines (38 loc) · 795 Bytes
/
hop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package registry
import (
"context"
"github.com/go-gost/core/chain"
)
type hopRegistry struct {
registry[chain.Hop]
}
func (r *hopRegistry) Register(name string, v chain.Hop) error {
return r.registry.Register(name, v)
}
func (r *hopRegistry) Get(name string) chain.Hop {
if name != "" {
return &hopWrapper{name: name, r: r}
}
return nil
}
func (r *hopRegistry) get(name string) chain.Hop {
return r.registry.Get(name)
}
type hopWrapper struct {
name string
r *hopRegistry
}
func (w *hopWrapper) Nodes() []*chain.Node {
v := w.r.get(w.name)
if v == nil {
return nil
}
return v.Nodes()
}
func (w *hopWrapper) Select(ctx context.Context, opts ...chain.SelectOption) *chain.Node {
v := w.r.get(w.name)
if v == nil {
return nil
}
return v.Select(ctx, opts...)
}