// buffer to store the message buf := new(bytes.Buffer) // create a new DNS message msg := new(dns.Msg) msg.SetReply(request) // add resource records to the message for _, rr := range records { msg.Answer = append(msg.Answer, rr) } // write the message to the client _, err = w.WriteMsg(msg) if err != nil { log.Printf("Error writing response: %v", err) }
c := new(dns.Client) msg := new(dns.Msg) msg.SetQuestion(dns.Fqdn(domainName), dns.TypeA) msg.RecursionDesired = true // send the query to the server and get the response res, _, err := c.Exchange(msg, serverAddress) if err != nil { log.Fatalf("Error querying %s: %s", serverAddress, err.Error()) } // write the response to the client w.WriteMsg(res)In this example, a DNS query is made using the dns.Client and dns.Msg libraries. The response to the query is then written to the client using the ResponseWriter WriteMsg function.