all: simply registering plugins (#3287)
Abstract the caddy call and make it simpler. See #3261 for some part of the discussion. Go from: ~~~ go func init() { caddy.RegisterPlugin("any", caddy.Plugin{ ServerType: "dns", Action: setup, }) } ~~~ To: ~~~ go func init() { plugin.Register("any", setup) } ~~~ This requires some external documents in coredns.io to be updated as well; the old way still works, so it's backwards compatible. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
85e65702bd
commit
004c5fca9d
38 changed files with 54 additions and 220 deletions
|
@ -13,12 +13,7 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("acl", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("acl", setup) }
|
||||
|
||||
func newDefaultFilter() *iptree.Tree {
|
||||
defaultFilter := iptree.NewTree()
|
||||
|
|
|
@ -7,12 +7,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("any", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("any", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
a := Any{}
|
||||
|
|
|
@ -18,12 +18,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("auto")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("auto", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("auto", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
a, err := autoParse(c)
|
||||
|
|
|
@ -11,13 +11,7 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("autopath", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
|
||||
}
|
||||
func init() { plugin.Register("autopath", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
ap, mw, err := autoPathParse(c)
|
||||
|
|
|
@ -17,12 +17,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("azure")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("azure", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("azure", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
env, keys, fall, err := parse(c)
|
||||
|
|
7
plugin/cache/setup.go
vendored
7
plugin/cache/setup.go
vendored
|
@ -16,12 +16,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("cache")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("cache", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("cache", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
ca, err := cacheParse(c)
|
||||
|
|
|
@ -11,13 +11,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("chaos", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
|
||||
}
|
||||
func init() { plugin.Register("chaos", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
version, authors, err := parse(c)
|
||||
|
|
|
@ -18,9 +18,8 @@ import (
|
|||
var log = clog.NewWithPlugin("clouddns")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("clouddns", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: func(c *caddy.Controller) error {
|
||||
plugin.Register("clouddns",
|
||||
func(c *caddy.Controller) error {
|
||||
f := func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) {
|
||||
var err error
|
||||
var client *gcp.Service
|
||||
|
@ -35,7 +34,7 @@ func init() {
|
|||
}
|
||||
return setup(c, f)
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
func setup(c *caddy.Controller, f func(ctx context.Context, opt option.ClientOption) (gcpDNS, error)) error {
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
)
|
||||
|
||||
// removed has the names of the plugins that need to error on startup.
|
||||
var removed = []string{"reverse"}
|
||||
var removed = []string{""}
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
c.Next()
|
||||
|
@ -29,10 +29,7 @@ func setup(c *caddy.Controller) error {
|
|||
}
|
||||
|
||||
func init() {
|
||||
for _, plugin := range removed {
|
||||
caddy.RegisterPlugin(plugin, caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
for _, plug := range removed {
|
||||
plugin.Register(plug, setup)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("dnssec")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("dnssec", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("dnssec", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
zones, keys, capacity, splitkeys, err := dnssecParse(c)
|
||||
|
|
|
@ -15,12 +15,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("dnstap")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("dnstap", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: wrapSetup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("dnstap", wrapSetup) }
|
||||
|
||||
func wrapSetup(c *caddy.Controller) error {
|
||||
if err := setup(c); err != nil {
|
||||
|
|
|
@ -11,12 +11,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("erratic", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("erratic", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
e, err := parseErratic(c)
|
||||
|
|
|
@ -10,12 +10,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("errors", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("errors", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
handler, err := errorsParse(c)
|
||||
|
|
|
@ -15,12 +15,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("etcd")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("etcd", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("etcd", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
e, err := etcdParse(c)
|
||||
|
|
|
@ -13,12 +13,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("file", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("file", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
zones, err := fileParse(c)
|
||||
|
|
|
@ -16,12 +16,7 @@ import (
|
|||
"github.com/caddyserver/caddy/caddyfile"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("forward", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("forward", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
f, err := parseForward(c)
|
||||
|
|
|
@ -14,12 +14,7 @@ import (
|
|||
"github.com/caddyserver/caddy/caddyfile"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("grpc", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("grpc", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
g, err := parseGRPC(c)
|
||||
|
|
|
@ -11,12 +11,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("health", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("health", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
addr, lame, err := parse(c)
|
||||
|
|
|
@ -17,12 +17,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("hosts")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("hosts", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("hosts", setup) }
|
||||
|
||||
func periodicHostsUpdate(h *Hosts) chan bool {
|
||||
parseChan := make(chan bool)
|
||||
|
|
|
@ -9,12 +9,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("k8s_external", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("k8s_external", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
e, err := parse(c)
|
||||
|
|
|
@ -34,12 +34,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("kubernetes")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("kubernetes", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("kubernetes", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
klog.SetOutput(os.Stdout)
|
||||
|
|
|
@ -12,12 +12,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("loadbalance")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("loadbalance", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("loadbalance", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
err := parse(c)
|
||||
|
|
|
@ -12,12 +12,7 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("log", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("log", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
rules, err := logParse(c)
|
||||
|
|
|
@ -13,12 +13,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("loop", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("loop", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
l, err := parse(c)
|
||||
|
|
|
@ -7,12 +7,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("metadata", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("metadata", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
m, err := metadataParse(c)
|
||||
|
|
|
@ -20,12 +20,7 @@ var (
|
|||
registry = newReg()
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("prometheus", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("prometheus", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
m, err := parse(c)
|
||||
|
|
|
@ -10,12 +10,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("nsid", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("nsid", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
nsid, err := nsidParse(c)
|
||||
|
|
|
@ -15,12 +15,7 @@ var log = clog.NewWithPlugin("pprof")
|
|||
|
||||
const defaultAddr = "localhost:6053"
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("pprof", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("pprof", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
h := &handler{addr: defaultAddr}
|
||||
|
|
|
@ -9,12 +9,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("ready", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("ready", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
addr, err := parse(c)
|
||||
|
|
11
plugin/register.go
Normal file
11
plugin/register.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package plugin
|
||||
|
||||
import "github.com/caddyserver/caddy"
|
||||
|
||||
// Register registers your plugin with CoreDNS and allows it to be called when the server is running.
|
||||
func Register(name string, action caddy.SetupFunc) {
|
||||
caddy.RegisterPlugin(name, caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: action,
|
||||
})
|
||||
}
|
|
@ -14,12 +14,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("reload")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("reload", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("reload", setup) }
|
||||
|
||||
// the info reload is global to all application, whatever number of reloads.
|
||||
// it is used to transmit data between Setup and start of the hook called 'onInstanceStartup'
|
||||
|
|
|
@ -10,12 +10,7 @@ import (
|
|||
|
||||
var log = clog.NewWithPlugin("rewrite")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("rewrite", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("rewrite", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
rewrites, err := rewriteParse(c)
|
||||
|
|
|
@ -25,9 +25,8 @@ import (
|
|||
var log = clog.NewWithPlugin("route53")
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("route53", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: func(c *caddy.Controller) error {
|
||||
plugin.Register("route53",
|
||||
func(c *caddy.Controller) error {
|
||||
f := func(credential *credentials.Credentials) route53iface.Route53API {
|
||||
return route53.New(session.Must(session.NewSession(&aws.Config{
|
||||
Credentials: credential,
|
||||
|
@ -35,7 +34,7 @@ func init() {
|
|||
}
|
||||
return setup(c, f)
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Route53API) error {
|
||||
|
|
|
@ -10,12 +10,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("secondary", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("secondary", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
zones, err := secondaryParse(c)
|
||||
|
|
|
@ -12,12 +12,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("sign", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("sign", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
sign, err := parse(c)
|
||||
|
|
|
@ -12,12 +12,7 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("template", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setupTemplate,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("template", setupTemplate) }
|
||||
|
||||
func setupTemplate(c *caddy.Controller) error {
|
||||
handler, err := templateParse(c)
|
||||
|
|
|
@ -11,12 +11,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("trace", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("trace", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
t, err := traceParse(c)
|
||||
|
|
|
@ -7,12 +7,7 @@ import (
|
|||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("whoami", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
Action: setup,
|
||||
})
|
||||
}
|
||||
func init() { plugin.Register("whoami", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
c.Next() // 'whoami'
|
||||
|
|
Loading…
Add table
Reference in a new issue