dns/example_test.go

68 lines
1.5 KiB
Go
Raw Normal View History

2012-09-02 17:02:59 +10:00
package dns
import (
"fmt"
)
// Retrieve the MX records for miek.nl.
func ExampleRR_MX() {
config, _ := ClientConfigFromFile("/etc/resolv.conf")
c := new(Client)
m := new(Msg)
m.SetQuestion("miek.nl.", TypeMX)
m.RecursionDesired = true
r, err := c.Exchange(m, config.Servers[0]+":"+config.Port)
if err != nil {
return
}
if r.Rcode != RcodeSuccess {
return
}
for _, a := range r.Answer {
if mx, ok := a.(*RR_MX); ok {
fmt.Printf("%s\n", mx.String())
}
}
}
2012-09-03 20:02:37 +10:00
// Retrieve the DNSKEY records of a zone and convert them
// to DS records for SHA1, SHA256 and SHA384.
func ExampleToDs(zone string) {
config, _ := ClientConfigFromFile("/etc/resolv.conf")
c := new(Client)
m := new(Msg)
if zone == "" {
zone = "miek.nl"
}
m.SetQuestion(Fqdn(zone), TypeDNSKEY)
m.SetEdns0(4096, true)
r, err := c.Exchange(m, config.Servers[0]+":"+config.Port)
if err != nil {
return
}
if r.Rcode != RcodeSuccess {
return
}
for _, k := range r.Answer {
if key, ok := k.(*RR_DNSKEY); ok {
for _, alg := range []int{SHA1, SHA256, SHA384} {
fmt.Printf("%s; %d\n", key.ToDS(alg).String(), key.Flags)
}
}
}
}
2012-09-03 21:16:16 +10:00
// Show how to setup the authors for 'authors.bind. CH TXT' or 'authors.server. CH TXT'
// queries.
func ExampleAuthors() {
// ... server setup is out of scope ...
HandleFunc("authors.bind.", HandleAuthors)
HandleFunc("authors.server.", HandleAuthors)
// To extend the authors list, just append to dns.Authors (a []string)
Authors = append(Authors, "G. I. Joe")
// Or
Authors = []string{"Just Me"}
}