mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	Add a new middleware that tells you who you are; IP, port and transport is echoed back. Also some various cleanup and documentation improvements while at it: * ResponseWriter: improve the documentation of these helper functions. * And add an NextHandler for use in tests. Make chaos_test.go and * whoam_test.go use it.
		
			
				
	
	
		
			29 lines
		
	
	
		
			524 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			524 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 dnsserver.Handler) dnsserver.Handler {
 | |
| 		return Whoami{Next: next}
 | |
| 	})
 | |
| 
 | |
| 	return nil
 | |
| }
 |