fix examples

This commit is contained in:
Miek Gieben 2012-05-22 08:51:30 +02:00
parent f3bb703019
commit c84b165dee
3 changed files with 6 additions and 6 deletions

View File

@ -109,13 +109,13 @@ func HandleQueryFunc(pattern string, handler func(RequestWriter, *Msg)) {
// //
// func main() { // func main() {
// dns.HandleQuery(".", myhandler) // dns.HandleQuery(".", myhandler)
// dns.ListenAndQuery(nil, nil) // use defaults // dns.ListenAndQuery(nil)
// m := new(dns.Msg) // m := new(dns.Msg)
// c := dns.NewClient() // c := dns.NewClient()
// m.SetQuestion("miek.nl.", TypeMX) // m.SetQuestion("miek.nl.", TypeMX)
// c.Do(m, "127.0.0.1:53") // c.Do(m, "127.0.0.1:53")
// // ... // // ...
// r := <- dns.Incoming // receive the reply in your program // r := <- dns.Reply
// } // }
func HandleQuery(pattern string, handler HandlerQueryFunc) { func HandleQuery(pattern string, handler HandlerQueryFunc) {
DefaultQueryMux.Handle(pattern, handler) DefaultQueryMux.Handle(pattern, handler)

View File

@ -27,12 +27,12 @@ func main() {
} }
for _, a := range addr { for _, a := range addr {
m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS} m.Question[0] = dns.Question{"version.bind.", dns.TypeTXT, dns.ClassCHAOS}
in, rtt, _, _ := c.ExchangeFull(m, a) in, rtt, _, _ := c.ExchangeRtt(m, a)
if in != nil && len(in.Answer) > 0 { if in != nil && len(in.Answer) > 0 {
fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0]) fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
} }
m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS} m.Question[0] = dns.Question{"hostname.bind.", dns.TypeTXT, dns.ClassCHAOS}
in, rtt, _, _ = c.ExchangeFull(m, a) in, rtt, _, _ = c.ExchangeRtt(m, a)
if in != nil && len(in.Answer) > 0 { if in != nil && len(in.Answer) > 0 {
fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0]) fmt.Printf("(time %.3d µs) %v\n", rtt/1e3, in.Answer[0])
} }
@ -66,7 +66,7 @@ func addresses(conf *dns.ClientConfig, c *dns.Client, name string) []string {
forever: forever:
for { for {
select { select {
case r := <-c.Incoming: case r := <-c.Reply:
if r.Reply != nil && r.Reply.Rcode == dns.RcodeSuccess { if r.Reply != nil && r.Reply.Rcode == dns.RcodeSuccess {
for _, aa := range r.Reply.Answer { for _, aa := range r.Reply.Answer {
switch aa.(type) { switch aa.(type) {

View File

@ -199,7 +199,7 @@ Flags:
forever: forever:
for { for {
select { select {
case r := <-c.Incoming: case r := <-c.Reply:
if r.Reply != nil { if r.Reply != nil {
if r.Reply.Rcode == dns.RcodeSuccess { if r.Reply.Rcode == dns.RcodeSuccess {
if r.Request.Id != r.Reply.Id { if r.Request.Id != r.Reply.Id {