coredns/middleware/pkg/debug/debug.go
Miek Gieben c4ab98c6e3 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.
2016-12-20 18:58:05 +00:00

21 lines
572 B
Go

package debug
import "strings"
// Name is the domain prefix we check for when it is a debug query.
const Name = "o-o.debug."
// IsDebug checks if name is a debugging name, i.e. starts with o-o.debug.
// it returns the empty string if it is not a debug message, otherwise it will return the
// name with o-o.debug. stripped off. Must be called with name lowercased.
func IsDebug(name string) string {
if len(name) == len(Name) {
return ""
}
name = strings.ToLower(name)
debug := strings.HasPrefix(name, Name)
if !debug {
return ""
}
return name[len(Name):]
}