]> Cypherpunks repositories - gostls13.git/commitdiff
net: remove more use of fmt
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 5 Mar 2012 20:20:58 +0000 (12:20 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 5 Mar 2012 20:20:58 +0000 (12:20 -0800)
Also add a TODO for the broken *dnsMsg String method.

R=golang-dev, rsc, borman
CC=golang-dev
https://golang.org/cl/5720075

src/pkg/net/dnsmsg.go
src/pkg/net/dnsmsg_test.go

index 97c5062103fe0f72920e9fe1589ff9265d9dd26c..4d1c8371ef0308775bddba2f5e3604f3f1c19baf 100644 (file)
@@ -24,8 +24,6 @@
 package net
 
 import (
-       "fmt"
-       "os"
        "reflect"
 )
 
@@ -394,7 +392,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
                f := val.Type().Field(i)
                switch fv := val.Field(i); fv.Kind() {
                default:
-                       fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type)
+                       println("net: dns: unknown packing type", f.Type.String())
                        return len(msg), false
                case reflect.Struct:
                        off, ok = packStructValue(fv, msg, off)
@@ -418,7 +416,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
                        off += 4
                case reflect.Array:
                        if fv.Type().Elem().Kind() != reflect.Uint8 {
-                               fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type)
+                               println("net: dns: unknown packing type", f.Type.String())
                                return len(msg), false
                        }
                        n := fv.Len()
@@ -433,7 +431,7 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
                        s := fv.String()
                        switch f.Tag {
                        default:
-                               fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag)
+                               println("net: dns: unknown string tag", string(f.Tag))
                                return len(msg), false
                        case `net:"domain-name"`:
                                off, ok = packDomainName(s, msg, off)
@@ -471,7 +469,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
                f := val.Type().Field(i)
                switch fv := val.Field(i); fv.Kind() {
                default:
-                       fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type)
+                       println("net: dns: unknown packing type", f.Type.String())
                        return len(msg), false
                case reflect.Struct:
                        off, ok = unpackStructValue(fv, msg, off)
@@ -491,7 +489,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
                        off += 4
                case reflect.Array:
                        if fv.Type().Elem().Kind() != reflect.Uint8 {
-                               fmt.Fprintf(os.Stderr, "net: dns: unknown packing type %v", f.Type)
+                               println("net: dns: unknown packing type", f.Type.String())
                                return len(msg), false
                        }
                        n := fv.Len()
@@ -504,7 +502,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
                        var s string
                        switch f.Tag {
                        default:
-                               fmt.Fprintf(os.Stderr, "net: dns: unknown string tag %v", f.Tag)
+                               println("net: dns: unknown string tag", string(f.Tag))
                                return len(msg), false
                        case `net:"domain-name"`:
                                s, off, ok = unpackDomainName(msg, off)
@@ -560,7 +558,9 @@ func printStructValue(val reflect.Value) string {
                        i := fv.Interface().([]byte)
                        s += IP(i).String()
                } else {
-                       s += fmt.Sprint(fval.Interface())
+                       // TODO(bradfitz,rsc): this next line panics (the String method of
+                       // *dnsMsg has been broken for awhile). Rewrite, ditch reflect.
+                       //s += fmt.Sprint(fval.Interface())
                }
        }
        s += "}"
index 06152a01a23eff0a50319ee86b8bb4beab9f3aba..58f53b74197bb22f7e5a37c51b5fbbf20a824eb3 100644 (file)
@@ -19,6 +19,7 @@ func TestDNSParseSRVReply(t *testing.T) {
        if !ok {
                t.Fatalf("unpacking packet failed")
        }
+       msg.String() // exercise this code path
        if g, e := len(msg.answer), 5; g != e {
                t.Errorf("len(msg.answer) = %d; want %d", g, e)
        }
@@ -50,6 +51,7 @@ func TestDNSParseCorruptSRVReply(t *testing.T) {
        if !ok {
                t.Fatalf("unpacking packet failed")
        }
+       msg.String() // exercise this code path
        if g, e := len(msg.answer), 5; g != e {
                t.Errorf("len(msg.answer) = %d; want %d", g, e)
        }