plugin/forward: Split setup to reuse it from external plugins
@@ -13,6 +13,7 @@ import (
pkgtls "github.com/coredns/coredns/plugin/pkg/tls"
"github.com/mholt/caddy"
+ "github.com/mholt/caddy/caddyfile"
)
func init() {
@@ -70,16 +71,29 @@ func (f *Forward) OnShutdown() error {
func (f *Forward) Close() { f.OnShutdown() }
func parseForward(c *caddy.Controller) (*Forward, error) {
- f := New()
-
- protocols := map[int]int{}
-
- i := 0
+ var (
+ f *Forward
+ err error
+ i int
+ )
for c.Next() {
if i > 0 {
return nil, plugin.ErrOnce
}
i++
+ f, err = ParseForwardStanza(&c.Dispenser)
+ if err != nil {
+ return nil, err
+ }
+ }
+ return f, nil
+}
+
+// ParseForwardStanza parses one forward stanza
+func ParseForwardStanza(c *caddyfile.Dispenser) (*Forward, error) {
+ f := New()
+
+ protocols := map[int]int{}
if !c.Args(&f.from) {
return f, c.ArgErr()
@@ -133,7 +147,6 @@ func parseForward(c *caddy.Controller) (*Forward, error) {
return f, err
}
}
- }
if f.tlsServerName != "" {
f.tlsConfig.ServerName = f.tlsServerName
@@ -148,7 +161,7 @@ func parseForward(c *caddy.Controller) (*Forward, error) {
return f, nil
}
-func parseBlock(c *caddy.Controller, f *Forward) error {
+func parseBlock(c *caddyfile.Dispenser, f *Forward) error {
switch c.Val() {
case "except":
ignore := c.RemainingArgs()
