-
Notifications
You must be signed in to change notification settings - Fork 41
/
ingress.go
48 lines (38 loc) · 954 Bytes
/
ingress.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/ingress"
)
type ingressRegistry struct {
registry[ingress.Ingress]
}
func (r *ingressRegistry) Register(name string, v ingress.Ingress) error {
return r.registry.Register(name, v)
}
func (r *ingressRegistry) Get(name string) ingress.Ingress {
if name != "" {
return &ingressWrapper{name: name, r: r}
}
return nil
}
func (r *ingressRegistry) get(name string) ingress.Ingress {
return r.registry.Get(name)
}
type ingressWrapper struct {
name string
r *ingressRegistry
}
func (w *ingressWrapper) GetRule(ctx context.Context, host string, opts ...ingress.Option) *ingress.Rule {
v := w.r.get(w.name)
if v == nil {
return nil
}
return v.GetRule(ctx, host, opts...)
}
func (w *ingressWrapper) SetRule(ctx context.Context, rule *ingress.Rule, opts ...ingress.Option) bool {
v := w.r.get(w.name)
if v == nil {
return false
}
return v.SetRule(ctx, rule, opts...)
}