coredns/plugin/pkg/upstream/upstream.go
Nguyen Hai Truong 39b0b91d6c Remove redundant words in comments (#2589)
Although it is spelling mistakes, it might make an affects
while reading.

Signed-off-by: Nguyen Hai Truong <truongnh@vn.fujitsu.com>
2019-02-20 18:20:48 -08:00

35 lines
965 B
Go

// Package upstream abstracts a upstream lookups so that plugins can handle them in an unified way.
package upstream
import (
"fmt"
"github.com/miekg/dns"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin/pkg/nonwriter"
"github.com/coredns/coredns/request"
)
// Upstream is used to resolve CNAME or other external targets via CoreDNS itself.
type Upstream struct{}
// New creates a new Upstream to resolve names using the coredns process.
func New() *Upstream { return &Upstream{} }
// Lookup routes lookups to our selves or forward to a remote.
func (u *Upstream) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error) {
server, ok := state.Context.Value(dnsserver.Key{}).(*dnsserver.Server)
if !ok {
return nil, fmt.Errorf("no full server is running")
}
req := new(dns.Msg)
req.SetQuestion(name, typ)
nw := nonwriter.New(state.W)
server.ServeDNS(state.Context, nw, req)
return nw.Msg, nil
}