-
Notifications
You must be signed in to change notification settings - Fork 19
/
forward.go
50 lines (39 loc) · 959 Bytes
/
forward.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
49
50
package alternate
import (
"fmt"
"time"
"github.com/coredns/caddy"
"github.com/coredns/coredns/plugin/forward"
"github.com/coredns/coredns/plugin/pkg/parse"
"github.com/coredns/coredns/plugin/pkg/proxy"
"github.com/coredns/coredns/plugin/pkg/transport"
)
const defaultExpire = 10 * time.Second
func initForward(c *caddy.Controller) (*forward.Forward, error) {
f := forward.New()
from := "."
if !c.Args(&from) {
return f, c.ArgErr()
}
to := c.RemainingArgs()
if len(to) == 0 {
return f, c.ArgErr()
}
toHosts, err := parse.HostPortOrFile(to...)
if err != nil {
return f, err
}
for c.NextBlock() {
return f, fmt.Errorf("additional parameters not allowed")
}
for _, host := range toHosts {
trans, h := parse.Transport(host)
if trans != transport.DNS {
return f, fmt.Errorf("only dns transport allowed")
}
p := proxy.NewProxy("alternate", h, trans)
p.SetExpire(defaultExpire)
f.SetProxy(p)
}
return f, nil
}