Add inline support for middleware/hosts (#1072)

This fix add inline support for middleware/hosts so that
it is possible to specify hosts file insides the Corefile:
```
hosts inline example.org {
    10.0.0.1 example.org
    fallthrough
}
```

This fix fixes 999.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2017-09-21 04:18:13 -07:00
committed by GitHub
parent aecf916377
commit 7109c6715c
5 changed files with 157 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"log"
"os"
"path"
"strings"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
@@ -80,6 +81,11 @@ func hostsParse(c *caddy.Controller) (Hosts, error) {
}
return h, c.ArgErr()
default:
if !h.Fallthrough {
line := strings.Join(append([]string{c.Val()}, c.RemainingArgs()...), " ")
h.inline = append(h.inline, line)
continue
}
return h, c.Errf("unknown property '%s'", c.Val())
}
}