Add middleware.NextOrFailure (#462)
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.
This commit is contained in:
parent
451a0bd529
commit
c4ab98c6e3
23 changed files with 51 additions and 67 deletions
|
@ -16,7 +16,7 @@ type RoundRobin struct {
|
|||
// ServeDNS implements the middleware.Handler interface.
|
||||
func (rr RoundRobin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
wrr := &RoundRobinResponseWriter{w}
|
||||
return rr.Next.ServeDNS(ctx, wrr, r)
|
||||
return middleware.NextOrFailure(rr.Name(), rr.Next, ctx, wrr, r)
|
||||
}
|
||||
|
||||
// Name implements the Handler interface.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue