THRIFT-1177. go: Update thrift to reflect changes in Go's networking libraries

Patch: Aalok Shah

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1146167 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/go/Make.deps b/lib/go/Make.deps
index c233e7e..56e75da 100644
--- a/lib/go/Make.deps
+++ b/lib/go/Make.deps
@@ -6,8 +6,10 @@
 bufio.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/bufio.a
 bytes.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/bytes.a
 cmath.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/cmath.a
+compress/bzip2.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/compress/bzip2.a
 compress/flate.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/compress/flate.a
 compress/gzip.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/compress/gzip.a
+compress/lzw.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/compress/lzw.a
 compress/zlib.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/compress/zlib.a
 container/heap.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/container/heap.a
 container/list.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/container/list.a
@@ -15,16 +17,22 @@
 container/vector.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/container/vector.a
 crypto.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto.a
 crypto/aes.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/aes.a
-crypto/block.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/block.a
 crypto/blowfish.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/blowfish.a
 crypto/cast5.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/cast5.a
 crypto/cipher.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/cipher.a
+crypto/des.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/des.a
 crypto/dsa.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/dsa.a
+crypto/ecdsa.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/ecdsa.a
 crypto/elliptic.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/elliptic.a
 crypto/hmac.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/hmac.a
 crypto/md4.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/md4.a
 crypto/md5.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/md5.a
 crypto/ocsp.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/ocsp.a
+crypto/openpgp.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/openpgp.a
+crypto/openpgp/armor.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/openpgp/armor.a
+crypto/openpgp/error.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/openpgp/error.a
+crypto/openpgp/packet.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/openpgp/packet.a
+crypto/openpgp/s2k.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/openpgp/s2k.a
 crypto/rand.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/rand.a
 crypto/rc4.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/rc4.a
 crypto/ripemd160.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/ripemd160.a
@@ -36,6 +44,7 @@
 crypto/tls.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/tls.a
 crypto/twofish.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/twofish.a
 crypto/x509.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/x509.a
+crypto/x509/crl.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/x509/crl.a
 crypto/xtea.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/crypto/xtea.a
 debug/dwarf.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/debug/dwarf.a
 debug/macho.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/debug/macho.a
@@ -67,17 +76,27 @@
 go/scanner.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/go/scanner.a
 go/token.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/go/token.a
 go/typechecker.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/go/typechecker.a
+go/types.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/go/types.a
 gob.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/gob.a
 hash.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/hash.a
 hash/adler32.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/hash/adler32.a
 hash/crc32.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/hash/crc32.a
 hash/crc64.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/hash/crc64.a
+hash/fnv.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/hash/fnv.a
 html.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/html.a
 http.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/http.a
+http/cgi.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/http/cgi.a
+http/fcgi.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/http/fcgi.a
 http/pprof.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/http/pprof.a
+http/httptest.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/http/httptest.a
+http/spdy.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/http/spdy.a
 image.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image.a
+image/bmp.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image/bmp.a
+image/gif.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image/gif.a
 image/jpeg.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image/jpeg.a
 image/png.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image/png.a
+image/tiff.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image/tiff.a
+image/ycbcr.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/image/ycbcr.a
 index/suffixarray.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/index/suffixarray.a
 io.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/io.a
 io/ioutil.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/io/ioutil.a
@@ -92,8 +111,10 @@
 netchan.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/netchan.a
 os.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/os.a
 os/signal.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/os/signal.a
+os/user.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/os/user.a
 patch.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/patch.a
 path.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/path.a
+path/filepath.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/path/filepath.a
 rand.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/rand.a
 reflect.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/reflect.a
 regexp.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/regexp.a
@@ -109,6 +130,7 @@
 strconv.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/strconv.a
 strings.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/strings.a
 sync.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/sync.a
+sync/atomic.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/sync/atomic.a
 syscall.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/syscall.a
 syslog.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/syslog.a
 tabwriter.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/tabwriter.a
@@ -127,8 +149,11 @@
 ../cmd/cgo.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/cgo.a
 ../cmd/ebnflint.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/ebnflint.a
 ../cmd/godoc.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/godoc.a
+../cmd/gofix.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/gofix.a
 ../cmd/gofmt.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/gofmt.a
 ../cmd/goinstall.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/goinstall.a
+../cmd/gotest.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/gotest.a
+../cmd/gotype.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/gotype.a
 ../cmd/govet.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/govet.a
 ../cmd/goyacc.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/goyacc.a
 ../cmd/hgpatch.install: ${GOROOT}/pkg/${GOOS}_${GOARCH}/../cmd/hgpatch.a
diff --git a/lib/go/thrift/thttp_client.go b/lib/go/thrift/thttp_client.go
index e09ecdf..08dd9ce 100644
--- a/lib/go/thrift/thttp_client.go
+++ b/lib/go/thrift/thttp_client.go
@@ -23,6 +23,7 @@
   "bytes"
   "http"
   "os"
+  "strconv"
 )
 
 
@@ -69,11 +70,11 @@
 
 
 func NewTHttpClient(url string) (TTransport, os.Error) {
-  response, finalUrl, err := http.Get(url)
+  parsedURL, err := http.ParseURL(url)
   if err != nil {
     return nil, err
   }
-  parsedURL, err := http.ParseURL(finalUrl)
+  response, err := http.Get(url)
   if err != nil {
     return nil, err
   }
@@ -139,7 +140,7 @@
   }
   if response.StatusCode != http.StatusOK {
     // TODO(pomack) log bad response
-    return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "HTTP Response code: "+string(response.StatusCode))
+    return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "HTTP Response code: "+ strconv.Itoa(response.StatusCode))
   }
   p.response = response
   return nil
diff --git a/lib/go/thrift/thttp_client_test.go b/lib/go/thrift/thttp_client_test.go
index 1af8cd3..fdd2f50 100644
--- a/lib/go/thrift/thttp_client_test.go
+++ b/lib/go/thrift/thttp_client_test.go
@@ -22,20 +22,13 @@
 import (
   . "thrift"
   "testing"
-  "http"
-  "net"
 )
 
 func TestHttpClient(t *testing.T) {
-  addr, err := FindAvailableTCPServerPort(40000)
-  if err != nil {
-    t.Fatalf("Unable to find available tcp port addr: %s", err)
+  l, addr := HttpClientSetupForTest(t)
+  if l != nil {
+    defer l.Close()
   }
-  l, err := net.Listen(addr.Network(), addr.String())
-  if err != nil {
-    t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
-  }
-  go http.Serve(l, &HTTPEchoServer{})
   trans, err := NewTHttpPostClient("http://" + addr.String())
   if err != nil {
     l.Close()
diff --git a/lib/go/thrift/tnonblocking_socket.go b/lib/go/thrift/tnonblocking_socket.go
index a1c0310..9b175b8 100644
--- a/lib/go/thrift/tnonblocking_socket.go
+++ b/lib/go/thrift/tnonblocking_socket.go
@@ -108,7 +108,7 @@
   }
 
   var err os.Error
-  if p.conn, err = net.Dial(p.addr.Network(), "", p.addr.String()); err != nil {
+  if p.conn, err = net.Dial(p.addr.Network(), p.addr.String()); err != nil {
     LOGGER.Print("Could not open socket", err.String())
     return NewTTransportException(NOT_OPEN, err.String())
   }
diff --git a/lib/go/thrift/tprotocol_test.go b/lib/go/thrift/tprotocol_test.go
index 22d6ad6..71ef8e9 100644
--- a/lib/go/thrift/tprotocol_test.go
+++ b/lib/go/thrift/tprotocol_test.go
@@ -25,7 +25,7 @@
   "http"
   "math"
   "net"
-  "io"
+  "io/ioutil"
   "os"
   "bytes"
   "fmt"
@@ -64,18 +64,26 @@
 type HTTPEchoServer struct{}
 
 func (p *HTTPEchoServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
-  w.WriteHeader(http.StatusOK)
-  io.Copy(w, req.Body)
+  buf, err := ioutil.ReadAll(req.Body)
+  if err != nil {
+    w.WriteHeader(http.StatusBadRequest)
+    w.Write(buf)
+  } else {
+    w.WriteHeader(http.StatusOK)
+    w.Write(buf)
+  }
 }
 
 func HttpClientSetupForTest(t *testing.T) (net.Listener, net.Addr) {
   addr, err := FindAvailableTCPServerPort(40000)
   if err != nil {
     t.Fatalf("Unable to find available tcp port addr: %s", err)
+    return nil, addr
   }
   l, err := net.Listen(addr.Network(), addr.String())
   if err != nil {
     t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
+    return l, addr
   }
   go http.Serve(l, &HTTPEchoServer{})
   return l, addr
@@ -85,6 +93,7 @@
 func ReadWriteProtocolTest(t *testing.T, protocolFactory TProtocolFactory) {
   buf := bytes.NewBuffer(make([]byte, 0, 1024))
   l, addr := HttpClientSetupForTest(t)
+  defer l.Close()
   transports := []TTransportFactory{
     NewTMemoryBufferTransportFactory(1024),
     NewTIOStreamTransportFactory(buf, buf, true),
@@ -164,7 +173,6 @@
   //  trans.Close()
   //}
 
-  l.Close()
 }
 
 func ReadWriteBool(t *testing.T, p TProtocol, trans TTransport) {
diff --git a/lib/go/thrift/tsocket.go b/lib/go/thrift/tsocket.go
index 758c132..3fc6253 100644
--- a/lib/go/thrift/tsocket.go
+++ b/lib/go/thrift/tsocket.go
@@ -134,7 +134,7 @@
     return NewTTransportException(NOT_OPEN, "Cannot open bad address.")
   }
   var err os.Error
-  if p.conn, err = net.Dial(p.addr.Network(), "", p.addr.String()); err != nil {
+  if p.conn, err = net.Dial(p.addr.Network(), p.addr.String()); err != nil {
     LOGGER.Print("Could not open socket", err.String())
     return NewTTransportException(NOT_OPEN, err.String())
   }
diff --git a/lib/go/thrift/ttransport.go b/lib/go/thrift/ttransport.go
index 45557f8..f29b0b4 100644
--- a/lib/go/thrift/ttransport.go
+++ b/lib/go/thrift/ttransport.go
@@ -22,6 +22,7 @@
 import (
   "os"
   "log"
+  "strconv"
 )
 
 type Flusher interface {
@@ -162,7 +163,7 @@
     ret, err = p.Read(buf[n:])
     if ret <= 0 {
       if err != nil {
-        err = NewTTransportExceptionDefaultString("Cannot read. Remote side has closed. Tried to read " + string(size) + " bytes, but only got " + string(n) + " bytes.")
+        err = NewTTransportExceptionDefaultString("Cannot read. Remote side has closed. Tried to read " + strconv.Itoa(size) + " bytes, but only got " + strconv.Itoa(n) + " bytes.")
       }
       return ret, err
     }
diff --git a/lib/go/thrift/ttransport_test.go b/lib/go/thrift/ttransport_test.go
index b9630de..4158a74 100644
--- a/lib/go/thrift/ttransport_test.go
+++ b/lib/go/thrift/ttransport_test.go
@@ -124,7 +124,7 @@
     l, err := net.Listen("tcp", s)
     if err == nil {
       l.Close()
-      return net.ResolveTCPAddr(s)
+      return net.ResolveTCPAddr("tcp", s)
     }
   }
   return nil, NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "Could not find available server port")