mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	This checks if the next middleware to be called is nil, and if so returns ServerFailure and an error. This makes the next calling more robust and saves some lines of code. Also prefix the error with the name of the middleware to aid in debugging.
		
			
				
	
	
		
			29 lines
		
	
	
		
			516 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			516 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package whoami
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/miekg/coredns/core/dnsserver"
 | 
						|
	"github.com/miekg/coredns/middleware"
 | 
						|
 | 
						|
	"github.com/mholt/caddy"
 | 
						|
)
 | 
						|
 | 
						|
func init() {
 | 
						|
	caddy.RegisterPlugin("whoami", caddy.Plugin{
 | 
						|
		ServerType: "dns",
 | 
						|
		Action:     setupWhoami,
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func setupWhoami(c *caddy.Controller) error {
 | 
						|
	c.Next() // 'whoami'
 | 
						|
	if c.NextArg() {
 | 
						|
		return middleware.Error("whoami", c.ArgErr())
 | 
						|
	}
 | 
						|
 | 
						|
	dnsserver.GetConfig(c).AddMiddleware(func(next middleware.Handler) middleware.Handler {
 | 
						|
		return Whoami{}
 | 
						|
	})
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 |