msg := &dns.Msg{} msg.SetQuestion("example.com.", dns.TypeA) msg.RecursionDesired = true client := &dns.Client{} resp, _, err := client.Exchange(msg, "8.8.8.8:53") if err == nil && resp.Rcode == dns.RcodeSuccess { // RecursionAvailable flag will be set in the response recursionAvail := resp.RecursionAvailable }
rr := &dns.A{ Hdr: dns.RR_Header{Name: "example.com.", Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}, A: net.IPv4(127, 0, 0, 1), } msg := &dns.Msg{} msg.Answer = []dns.RR{rr} msg.RecursionAvailable = true b, _ := msg.Pack()In this example, we create a DNS response for the "example.com" domain with an A record pointing to the loopback IP address. We then set the RecursionAvailable flag in the response to true, indicating that the server allows recursive queries. Finally, we pack the response into a byte slice using the msg.Pack() method from the "github.com/miekg/dns" package.