aboutsummaryrefslogtreecommitdiff
path: root/middleware/file/setup.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-10-11 20:42:28 +0100
committerGravatar GitHub <noreply@github.com> 2016-10-11 20:42:28 +0100
commit710c9b111f31b9d5f0b280739420b31c95adf14b (patch)
tree911351fb9fab47d9a9f23bbf9723491efb3d3b23 /middleware/file/setup.go
parentbaea5eef2fd33f99a0612d413311dc0a15889a77 (diff)
downloadcoredns-710c9b111f31b9d5f0b280739420b31c95adf14b.tar.gz
coredns-710c9b111f31b9d5f0b280739420b31c95adf14b.tar.zst
coredns-710c9b111f31b9d5f0b280739420b31c95adf14b.zip
middleware/root: add it (#330)
This PR adds the *root* middleware that specifies a path where all zone file (the *file* middleware is the only consumer now) can be found. It works the same as in Caddy. Documentation can be found in the README.md of the middleware. Fixes #307
Diffstat (limited to 'middleware/file/setup.go')
-rw-r--r--middleware/file/setup.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/middleware/file/setup.go b/middleware/file/setup.go
index dd1f17d9a..95e3209f4 100644
--- a/middleware/file/setup.go
+++ b/middleware/file/setup.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
+ "path"
"github.com/miekg/coredns/core/dnsserver"
"github.com/miekg/coredns/middleware"
@@ -49,6 +50,8 @@ func fileParse(c *caddy.Controller) (Zones, error) {
names := []string{}
origins := []string{}
+ config := dnsserver.GetConfig(c)
+
for c.Next() {
if c.Val() == "file" {
// file db.file [zones...]
@@ -64,6 +67,10 @@ func fileParse(c *caddy.Controller) (Zones, error) {
origins = args
}
+ if !path.IsAbs(fileName) && config.Root != "" {
+ fileName = path.Join(config.Root, fileName)
+ }
+
reader, err := os.Open(fileName)
if err != nil {
// bail out