dnsserver.go
func (ds *DNSServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
	m := &dns.Msg{}
	m.SetReply(r)

	answers := []dns.RR{}

	for _, question := range r.Question {
		// nil records == not found
		switch question.Qtype {
		case dns.TypeA:
			a := ds.GetA(question.Name)
			if a != nil {
				answers = append(answers, a)
			}
		case dns.TypeSRV:
			srv := ds.GetSRV(question.Name)

			if srv != nil {
				for _, record := range srv {
					answers = append(answers, record)
				}
			}
		}
	}

	// If we have no answers, that means we found nothing or didn't get a query
	// we can reply to. Reply with no answers so we ensure the query moves on to
	// the next server.
	if len(answers) == 0 {
		m.SetRcode(r, dns.RcodeSuccess)
		w.WriteMsg(m)
		return
	}

	// Without these the glibc resolver gets very angry.
	m.Authoritative = true
	m.RecursionAvailable = true
	m.Answer = answers

	w.WriteMsg(m)
}
func (ds *DNSServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
	m := &dns.Msg{}
	m.SetReply(r)

	answers := []dns.RR{}

	for _, question := range r.Question {
		// nil records == not found
		switch question.Qtype {
		case dns.TypeA:
			a := ds.GetA(question.Name)
			if a != nil {
				answers = append(answers, a)
			}
		case dns.TypeSRV:
			srv := ds.GetSRV(question.Name)

			if srv != nil {
				for _, record := range srv {
					answers = append(answers, record)
				}
			}
		}
	}

	// If we have no answers, that means we found nothing or didn't get a query
	// we can reply to. Reply with no answers so we ensure the query moves on to
	// the next server.
	if len(answers) == 0 {
		m.SetRcode(r, dns.RcodeSuccess)
		w.WriteMsg(m)
		return
	}

	// Without these the glibc resolver gets very angry.
	m.Authoritative = true
	m.RecursionAvailable = true
	m.Answer = answers

	w.WriteMsg(m)
}
func ( ds * DNSServer ) ServeDNS ( w dns . ResponseWriter , r * dns . Msg ) { m := & dns . Msg { } m . SetReply ( r ) answers := [ ] dns . RR { } for _ , question := range r . Question { // nil records == not found switch question . Qtype { case dns . TypeA : a := ds . GetA ( question . Name ) if a != nil { answers = append ( answers , a ) } case dns . TypeSRV : srv := ds . GetSRV ( question . Name ) if srv != nil { for _ , record := range srv { answers = append ( answers , record ) } } } } // If we have no answers, that means we found nothing or didn't get a query // we can reply to. Reply with no answers so we ensure the query moves on to // the next server. if len ( answers ) == 0 { m . SetRcode ( r , dns . RcodeSuccess ) w . WriteMsg ( m ) return } // Without these the glibc resolver gets very angry. m . Authoritative = true m . RecursionAvailable = true m . Answer = answers w . WriteMsg ( m ) }
// Main callback for miekg/dns. Collects information about the query,
// constructs a response, and returns it to the connector.
Main callback for miekg / dns . Collects information about the query constructs a response and returns it to the connector .