coredns/middleware/rewrite/name.go
Yong Tang 81af74aad0 Fix import path github.com/miekg/coredns -> github.com/coredns/coredns (#547)
This fix fixes import path from
`github.com/miekg/coredns`
->
`github.com/coredns/coredns`
2017-02-22 06:51:47 +00:00

29 lines
691 B
Go

// Package rewrite is middleware for rewriting requests internally to something different.
package rewrite
import (
"strings"
"github.com/coredns/coredns/middleware"
"github.com/miekg/dns"
)
// NameRule is a name rewrite rule.
type NameRule struct {
From, To string
}
// Initializer
func (rule NameRule) New(args ...string) Rule {
from, to := args[0], strings.Join(args[1:], " ")
return &NameRule{middleware.Name(from).Normalize(), middleware.Name(to).Normalize()}
}
// Rewrite rewrites the the current request.
func (rule NameRule) Rewrite(r *dns.Msg) Result {
if rule.From == r.Question[0].Name {
r.Question[0].Name = rule.To
return RewriteDone
}
return RewriteIgnored
}