mirror of
https://github.com/coredns/coredns.git
synced 2025-12-10 04:15:20 -05:00
middleware/whoami: add (#264)
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.
This commit is contained in:
28
middleware/whoami/setup.go
Normal file
28
middleware/whoami/setup.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user