1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

net: remove more use of fmt

Also add a TODO for the broken *dnsMsg String method.

R=golang-dev, rsc, borman
CC=golang-dev
https://golang.org/cl/5720075
This commit is contained in:
Brad Fitzpatrick 2012-03-05 12:20:58 -08:00
parent a55a6cb925
commit 7300b43c2b
2 changed files with 11 additions and 9 deletions

View 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 += "}"

View 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)
}