coredns/plugin/nsid/setup.go
Yong Tang f8bba51f84
Update Caddy to 1.0.1, and update import path (#2961)
* Update Caddy to 1.0.1, and update import path

This fix updates caddy to 1.0.1 and also
updates the import path to github.com/caddyserver/caddy

This fix fixes 2959

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Also update plugin.cfg

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Update and bump zplugin.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-07-03 09:04:47 +08:00

51 lines
867 B
Go

package nsid
import (
"os"
"strings"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/caddyserver/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"
}
i := 0
for c.Next() {
if i > 0 {
return nsid, plugin.ErrOnce
}
i++
args := c.RemainingArgs()
if len(args) > 0 {
nsid = strings.Join(args, " ")
}
}
return nsid, nil
}