package upstream
import (
"context"
"fmt"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin/pkg/nonwriter"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
type Upstream struct{}
func New() *Upstream { return &Upstream{} }
func (u *Upstream) Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error) {
server, ok := ctx.Value(dnsserver.Key{}).(*dnsserver.Server)
if !ok {
return nil, fmt.Errorf("no full server is running")
}
req := state.NewWithQuestion(name, typ)
nw := nonwriter.New(state.W)
server.ServeDNS(ctx, nw, req.Req)
return nw.Msg, nil
}