Remove the word middleware (#1067)

* Rename middleware to plugin

first pass; mostly used 'sed', few spots where I manually changed
text.

This still builds a coredns binary.

* fmt error

* Rename AddMiddleware to AddPlugin

* Readd AddMiddleware to remain backwards compat
This commit is contained in:
Miek Gieben
2017-09-14 09:36:06 +01:00
committed by GitHub
parent b984aa4559
commit d8714e64e4
354 changed files with 974 additions and 969 deletions

View File

@@ -6,27 +6,27 @@ import (
_ "github.com/coredns/coredns/core/dnsserver"
// plug in the standard directives (sorted)
_ "github.com/coredns/coredns/middleware/auto"
_ "github.com/coredns/coredns/middleware/bind"
_ "github.com/coredns/coredns/middleware/cache"
_ "github.com/coredns/coredns/middleware/chaos"
_ "github.com/coredns/coredns/middleware/dnssec"
_ "github.com/coredns/coredns/middleware/dnstap"
_ "github.com/coredns/coredns/middleware/erratic"
_ "github.com/coredns/coredns/middleware/errors"
_ "github.com/coredns/coredns/middleware/etcd"
_ "github.com/coredns/coredns/middleware/file"
_ "github.com/coredns/coredns/middleware/health"
_ "github.com/coredns/coredns/middleware/kubernetes"
_ "github.com/coredns/coredns/middleware/loadbalance"
_ "github.com/coredns/coredns/middleware/log"
_ "github.com/coredns/coredns/middleware/metrics"
_ "github.com/coredns/coredns/middleware/pprof"
_ "github.com/coredns/coredns/middleware/proxy"
_ "github.com/coredns/coredns/middleware/reverse"
_ "github.com/coredns/coredns/middleware/rewrite"
_ "github.com/coredns/coredns/middleware/root"
_ "github.com/coredns/coredns/middleware/secondary"
_ "github.com/coredns/coredns/middleware/trace"
_ "github.com/coredns/coredns/middleware/whoami"
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/etcd"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/kubernetes"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reverse"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/trace"
_ "github.com/coredns/coredns/plugin/whoami"
)

View File

@@ -3,7 +3,7 @@ package dnsserver
import (
"strings"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/plugin"
"github.com/miekg/dns"
)
@@ -50,7 +50,7 @@ func normalizeZone(str string) (zoneAddr, error) {
str = str[len(TransportGRPC+"://"):]
}
host, port, err := middleware.SplitHostPort(str)
host, port, err := plugin.SplitHostPort(str)
if err != nil {
return zoneAddr{}, err
}

View File

@@ -3,8 +3,7 @@ package dnsserver
import (
"crypto/tls"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/plugin"
"github.com/mholt/caddy"
)
@@ -20,7 +19,7 @@ type Config struct {
Port string
// Root points to a base directory we we find user defined "things".
// First consumer is the file middleware to looks for zone files in this place.
// First consumer is the file plugin to looks for zone files in this place.
Root string
// Debug controls the panic/recover mechanism that is enabled by default.
@@ -33,16 +32,16 @@ type Config struct {
// TLSConfig when listening for encrypted connections (gRPC, DNS-over-TLS).
TLSConfig *tls.Config
// Middleware stack.
Middleware []middleware.Middleware
// Plugin stack.
Plugin []plugin.Plugin
// Compiled middleware stack.
middlewareChain middleware.Handler
// Compiled plugin stack.
pluginChain plugin.Handler
// Middleware interested in announcing that they exist, so other middleware can call methods
// Plugin interested in announcing that they exist, so other plugin can call methods
// on them should register themselves here. The name should be the name as return by the
// Handler's Name method.
registry map[string]middleware.Handler
registry map[string]plugin.Handler
}
// GetConfig gets the Config that corresponds to c.

View File

@@ -6,7 +6,7 @@ import (
"net"
"time"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/plugin"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyfile"
@@ -119,27 +119,33 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
return servers, nil
}
// AddMiddleware adds a middleware to a site's middleware stack.
func (c *Config) AddMiddleware(m middleware.Middleware) {
c.Middleware = append(c.Middleware, m)
// AddPlugin adds a plugin to a site's plugin stack.
func (c *Config) AddPlugin(m plugin.Plugin) {
c.Plugin = append(c.Plugin, m)
}
// AddMiddleware adds a plugin to a site's plugin stack. This method is deprecated, use AddPlugin.
func (c *Config) AddMiddleware(m plugin.Plugin) {
println("deprecated: use AddPlugin")
c.AddPlugin(m)
}
// registerHandler adds a handler to a site's handler registration. Handlers
// use this to announce that they exist to other middleware.
func (c *Config) registerHandler(h middleware.Handler) {
// use this to announce that they exist to other plugin.
func (c *Config) registerHandler(h plugin.Handler) {
if c.registry == nil {
c.registry = make(map[string]middleware.Handler)
c.registry = make(map[string]plugin.Handler)
}
// Just overwrite...
c.registry[h.Name()] = h
}
// Handler returns the middleware handler that has been added to the config under its name.
// This is useful to inspect if a certain middleware is active in this server.
// Note that this is order dependent and the order is defined in directives.go, i.e. if your middleware
// comes before the middleware you are checking; it will not be there (yet).
func (c *Config) Handler(name string) middleware.Handler {
// Handler returns the plugin handler that has been added to the config under its name.
// This is useful to inspect if a certain plugin is active in this server.
// Note that this is order dependent and the order is defined in directives.go, i.e. if your plugin
// comes before the plugin you are checking; it will not be there (yet).
func (c *Config) Handler(name string) plugin.Handler {
if c.registry == nil {
return nil
}

View File

@@ -24,7 +24,7 @@ type ServergRPC struct {
listenAddr net.Addr
}
// NewServergRPC returns a new CoreDNS GRPC server and compiles all middleware in to it.
// NewServergRPC returns a new CoreDNS GRPC server and compiles all plugin in to it.
func NewServergRPC(addr string, group []*Config) (*ServergRPC, error) {
s, err := NewServer(addr, group)
@@ -62,7 +62,7 @@ func (s *ServergRPC) ServePacket(p net.PacketConn) error { return nil }
// Listen implements caddy.TCPServer interface.
func (s *ServergRPC) Listen() (net.Listener, error) {
// The *tls* middleware must make sure that multiple conflicting
// The *tls* plugin must make sure that multiple conflicting
// TLS configuration return an error: it can only be specified once.
tlsConfig := new(tls.Config)
for _, conf := range s.zones {

View File

@@ -14,7 +14,7 @@ type ServerTLS struct {
*Server
}
// NewServerTLS returns a new CoreDNS TLS server and compiles all middleware in to it.
// NewServerTLS returns a new CoreDNS TLS server and compiles all plugin in to it.
func NewServerTLS(addr string, group []*Config) (*ServerTLS, error) {
s, err := NewServer(addr, group)
if err != nil {
@@ -43,7 +43,7 @@ func (s *ServerTLS) ServePacket(p net.PacketConn) error { return nil }
// Listen implements caddy.TCPServer interface.
func (s *ServerTLS) Listen() (net.Listener, error) {
// The *tls* middleware must make sure that multiple conflicting
// The *tls* plugin must make sure that multiple conflicting
// TLS configuration return an error: it can only be specified once.
tlsConfig := new(tls.Config)
for _, conf := range s.zones {

View File

@@ -9,11 +9,11 @@ import (
"sync"
"time"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/middleware/metrics/vars"
"github.com/coredns/coredns/middleware/pkg/edns"
"github.com/coredns/coredns/middleware/pkg/rcode"
"github.com/coredns/coredns/middleware/pkg/trace"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics/vars"
"github.com/coredns/coredns/plugin/pkg/edns"
"github.com/coredns/coredns/plugin/pkg/rcode"
"github.com/coredns/coredns/plugin/pkg/trace"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
@@ -35,12 +35,12 @@ type Server struct {
zones map[string]*Config // zones keyed by their address
dnsWg sync.WaitGroup // used to wait on outstanding connections
connTimeout time.Duration // the maximum duration of a graceful shutdown
trace trace.Trace // the trace middleware for the server
trace trace.Trace // the trace plugin for the server
debug bool // disable recover()
classChaos bool // allow non-INET class queries
}
// NewServer returns a new CoreDNS server and compiles all middleware in to it. By default CH class
// NewServer returns a new CoreDNS server and compiles all plugin in to it. By default CH class
// queries are blocked unless the chaos or proxy is loaded.
func NewServer(addr string, group []*Config) (*Server, error) {
@@ -64,16 +64,16 @@ func NewServer(addr string, group []*Config) (*Server, error) {
}
// set the config per zone
s.zones[site.Zone] = site
// compile custom middleware for everything
var stack middleware.Handler
for i := len(site.Middleware) - 1; i >= 0; i-- {
stack = site.Middleware[i](stack)
// compile custom plugin for everything
var stack plugin.Handler
for i := len(site.Plugin) - 1; i >= 0; i-- {
stack = site.Plugin[i](stack)
// register the *handler* also
site.registerHandler(stack)
if s.trace == nil && stack.Name() == "trace" {
// we have to stash away the middleware, not the
// we have to stash away the plugin, not the
// Tracer object, because the Tracer won't be initialized yet
if t, ok := stack.(trace.Trace); ok {
s.trace = t
@@ -83,7 +83,7 @@ func NewServer(addr string, group []*Config) (*Server, error) {
s.classChaos = true
}
}
site.middlewareChain = stack
site.pluginChain = stack
}
return s, nil
@@ -177,11 +177,11 @@ func (s *Server) Address() string { return s.Addr }
// ServeDNS is the entry point for every request to the address that s
// is bound to. It acts as a multiplexer for the requests zonename as
// defined in the request so that the correct zone
// (configuration and middleware stack) will handle the request.
// (configuration and plugin stack) will handle the request.
func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) {
if !s.debug {
defer func() {
// In case the user doesn't enable error middleware, we still
// In case the user doesn't enable error plugin, we still
// need to make sure that we stay alive up here
if rec := recover(); rec != nil {
DefaultErrorFunc(w, r, dns.RcodeServerFailure)
@@ -218,8 +218,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
if h, ok := s.zones[string(b[:l])]; ok {
if r.Question[0].Qtype != dns.TypeDS {
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
if !middleware.ClientWrite(rcode) {
rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
if !plugin.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode)
}
return
@@ -239,8 +239,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
if dshandler != nil {
// DS request, and we found a zone, use the handler for the query
rcode, _ := dshandler.middlewareChain.ServeDNS(ctx, w, r)
if !middleware.ClientWrite(rcode) {
rcode, _ := dshandler.pluginChain.ServeDNS(ctx, w, r)
if !plugin.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode)
}
return
@@ -248,8 +248,8 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
// Wildcard match, if we have found nothing try the root zone as a last resort.
if h, ok := s.zones["."]; ok {
rcode, _ := h.middlewareChain.ServeDNS(ctx, w, r)
if !middleware.ClientWrite(rcode) {
rcode, _ := h.pluginChain.ServeDNS(ctx, w, r)
if !plugin.ClientWrite(rcode) {
DefaultErrorFunc(w, r, rcode)
}
return

View File

@@ -5,10 +5,10 @@ package dnsserver
// Directives are registered in the order they should be
// executed.
//
// Ordering is VERY important. Every middleware will
// feel the effects of all other middleware below
// Ordering is VERY important. Every plugin will
// feel the effects of all other plugin below
// (after) them during a request, but they must not
// care what middleware above them are doing.
// care what plugin above them are doing.
var directives = []string{
"tls",

View File

@@ -1,36 +0,0 @@
// generated by directives_generate.go; DO NOT EDIT
package core
import (
// Include all middleware.
_ "github.com/coredns/coredns/middleware/auto"
_ "github.com/coredns/coredns/middleware/autopath"
_ "github.com/coredns/coredns/middleware/bind"
_ "github.com/coredns/coredns/middleware/cache"
_ "github.com/coredns/coredns/middleware/chaos"
_ "github.com/coredns/coredns/middleware/debug"
_ "github.com/coredns/coredns/middleware/dnssec"
_ "github.com/coredns/coredns/middleware/dnstap"
_ "github.com/coredns/coredns/middleware/erratic"
_ "github.com/coredns/coredns/middleware/errors"
_ "github.com/coredns/coredns/middleware/etcd"
_ "github.com/coredns/coredns/middleware/federation"
_ "github.com/coredns/coredns/middleware/file"
_ "github.com/coredns/coredns/middleware/health"
_ "github.com/coredns/coredns/middleware/hosts"
_ "github.com/coredns/coredns/middleware/kubernetes"
_ "github.com/coredns/coredns/middleware/loadbalance"
_ "github.com/coredns/coredns/middleware/log"
_ "github.com/coredns/coredns/middleware/metrics"
_ "github.com/coredns/coredns/middleware/pprof"
_ "github.com/coredns/coredns/middleware/proxy"
_ "github.com/coredns/coredns/middleware/reverse"
_ "github.com/coredns/coredns/middleware/rewrite"
_ "github.com/coredns/coredns/middleware/root"
_ "github.com/coredns/coredns/middleware/secondary"
_ "github.com/coredns/coredns/middleware/tls"
_ "github.com/coredns/coredns/middleware/trace"
_ "github.com/coredns/coredns/middleware/whoami"
_ "github.com/mholt/caddy/startupshutdown"
)

36
core/zplugin.go Normal file
View File

@@ -0,0 +1,36 @@
// generated by directives_generate.go; DO NOT EDIT
package core
import (
// Include all plugin.
_ "github.com/coredns/coredns/plugin/auto"
_ "github.com/coredns/coredns/plugin/autopath"
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
_ "github.com/coredns/coredns/plugin/chaos"
_ "github.com/coredns/coredns/plugin/debug"
_ "github.com/coredns/coredns/plugin/dnssec"
_ "github.com/coredns/coredns/plugin/dnstap"
_ "github.com/coredns/coredns/plugin/erratic"
_ "github.com/coredns/coredns/plugin/errors"
_ "github.com/coredns/coredns/plugin/etcd"
_ "github.com/coredns/coredns/plugin/federation"
_ "github.com/coredns/coredns/plugin/file"
_ "github.com/coredns/coredns/plugin/health"
_ "github.com/coredns/coredns/plugin/hosts"
_ "github.com/coredns/coredns/plugin/kubernetes"
_ "github.com/coredns/coredns/plugin/loadbalance"
_ "github.com/coredns/coredns/plugin/log"
_ "github.com/coredns/coredns/plugin/metrics"
_ "github.com/coredns/coredns/plugin/pprof"
_ "github.com/coredns/coredns/plugin/proxy"
_ "github.com/coredns/coredns/plugin/reverse"
_ "github.com/coredns/coredns/plugin/rewrite"
_ "github.com/coredns/coredns/plugin/root"
_ "github.com/coredns/coredns/plugin/secondary"
_ "github.com/coredns/coredns/plugin/tls"
_ "github.com/coredns/coredns/plugin/trace"
_ "github.com/coredns/coredns/plugin/whoami"
_ "github.com/mholt/caddy/startupshutdown"
)