coredns/plugin/header/setup.go
Miek Gieben 50d888f3d7
plugin/header: run go gen and small doc updates (#4754)
* plugin/header: run go gen and small doc updates

Run go gen to enable the new plugin, this should fix the CI failures.
Small tweaks to the docs.

Signed-off-by: Miek Gieben <miek@miek.nl>

* another typo

Signed-off-by: Miek Gieben <miek@miek.nl>

* gofmt

Signed-off-by: Miek Gieben <miek@miek.nl>
2021-07-15 10:10:16 +02:00

50 lines
887 B
Go

package header
import (
"fmt"
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
)
func init() { plugin.Register("header", setup) }
func setup(c *caddy.Controller) error {
rules, err := parse(c)
if err != nil {
return plugin.Error("header", err)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
return Header{
Rules: rules,
Next: next,
}
})
return nil
}
func parse(c *caddy.Controller) ([]Rule, error) {
for c.Next() {
var all []Rule
for c.NextBlock() {
v := c.Val()
args := c.RemainingArgs()
// set up rules
rules, err := newRules(v, args)
if err != nil {
return nil, fmt.Errorf("seting up rule: %w", err)
}
all = append(all, rules...)
}
// return combined rules
if len(all) > 0 {
return all, nil
}
}
return nil, c.ArgErr()
}