mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
Add NSID plugin support for CoreDNS (#1273)
* Add NSID plugin support for CoreDNS This fix adds NSID plugin support for CoreDNS, as was proposed in 1256. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Add test cases for NSID plugin Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Generate code for NSID plugin Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Use hostname as the default (as with bind), and remove unneeded copy Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Add README.md Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
48
plugin/nsid/setup.go
Normal file
48
plugin/nsid/setup.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package nsid
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("nsid", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
nsid, err := nsidParse(c)
|
||||
if err != nil {
|
||||
return plugin.Error("nsid", err)
|
||||
}
|
||||
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
return Nsid{Next: next, Data: nsid}
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func nsidParse(c *caddy.Controller) (string, error) {
|
||||
// Use hostname as the default
|
||||
nsid, err := os.Hostname()
|
||||
if err != nil {
|
||||
nsid = "localhost"
|
||||
}
|
||||
for c.Next() {
|
||||
args := c.RemainingArgs()
|
||||
if len(args) == 0 {
|
||||
return nsid, nil
|
||||
}
|
||||
nsid = strings.Join(args, " ")
|
||||
return nsid, nil
|
||||
}
|
||||
return nsid, nil
|
||||
}
|
||||
Reference in New Issue
Block a user