diff options
author | 2017-12-13 10:18:08 -0600 | |
---|---|---|
committer | 2017-12-13 11:18:08 -0500 | |
commit | 556a289d9a2ec04583b26c89712000aac578ae89 (patch) | |
tree | f62d4d7655f69c06cc1e64a52a0ba6cb293a02d9 /plugin/file/setup.go | |
parent | a469a17cdfccfb435f819ebdf7ff7b43b207c8b4 (diff) | |
download | coredns-556a289d9a2ec04583b26c89712000aac578ae89.tar.gz coredns-556a289d9a2ec04583b26c89712000aac578ae89.tar.zst coredns-556a289d9a2ec04583b26c89712000aac578ae89.zip |
Moving TransferParse from file to its own package (#1286)
* Moving TransferParse from file to its own package
* Adding tests for parse
Diffstat (limited to 'plugin/file/setup.go')
-rw-r--r-- | plugin/file/setup.go | 43 |
1 files changed, 2 insertions, 41 deletions
diff --git a/plugin/file/setup.go b/plugin/file/setup.go index bf0523c54..3c25b4f7d 100644 --- a/plugin/file/setup.go +++ b/plugin/file/setup.go @@ -1,13 +1,13 @@ package file import ( - "fmt" "os" "path" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/pkg/dnsutil" + "github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/proxy" "github.com/mholt/caddy" @@ -97,7 +97,7 @@ func fileParse(c *caddy.Controller) (Zones, error) { for c.NextBlock() { switch c.Val() { case "transfer": - t, _, e = TransferParse(c, false) + t, _, e = parse.Transfer(c, false) if e != nil { return Zones{}, e } @@ -130,42 +130,3 @@ func fileParse(c *caddy.Controller) (Zones, error) { } return Zones{Z: z, Names: names}, nil } - -// TransferParse parses transfer statements: 'transfer to [address...]'. -func TransferParse(c *caddy.Controller, secondary bool) (tos, froms []string, err error) { - if !c.NextArg() { - return nil, nil, c.ArgErr() - } - value := c.Val() - switch value { - case "to": - tos = c.RemainingArgs() - for i := range tos { - if tos[i] != "*" { - normalized, err := dnsutil.ParseHostPort(tos[i], "53") - if err != nil { - return nil, nil, err - } - tos[i] = normalized - } - } - - case "from": - if !secondary { - return nil, nil, fmt.Errorf("can't use `transfer from` when not being a secondary") - } - froms = c.RemainingArgs() - for i := range froms { - if froms[i] != "*" { - normalized, err := dnsutil.ParseHostPort(froms[i], "53") - if err != nil { - return nil, nil, err - } - froms[i] = normalized - } else { - return nil, nil, fmt.Errorf("can't use '*' in transfer from") - } - } - } - return -} |