-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolicy.go
More file actions
32 lines (28 loc) · 795 Bytes
/
policy.go
File metadata and controls
32 lines (28 loc) · 795 Bytes
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
package conditional
import (
"context"
"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/request"
"github.com/infobloxopen/fwdpolicy"
)
func (c *Conditional) String() string { return "conditional" }
func (c *Conditional) List(ctx context.Context, p []*fwdpolicy.Proxy, state *request.Request) []*fwdpolicy.Proxy {
params := Parameters{ctx: ctx, state: state, extractors: c.extractors}
for _, r := range c.fwdRules {
result, err := r.expr.Eval(params)
if err != nil {
return nil
}
if b, ok := result.(bool); ok && b {
ups := make([]*fwdpolicy.Proxy, len(r.upstreams))
for i, n := range r.upstreams {
ups[i] = p[n]
}
metadata.SetValueFunc(ctx, "forward/group", func() string {
return r.group
})
return ups
}
}
return nil
}