You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2011/07/13 19:58:06 UTC

svn commit: r1146167 - in /thrift/trunk: compiler/cpp/src/generate/ lib/go/ lib/go/thrift/

Author: bryanduxbury
Date: Wed Jul 13 17:58:05 2011
New Revision: 1146167

URL: http://svn.apache.org/viewvc?rev=1146167&view=rev
Log:
THRIFT-1177. go: Update thrift to reflect changes in Go's networking libraries

Patch: Aalok Shah

Modified:
    thrift/trunk/compiler/cpp/src/generate/t_go_generator.cc
    thrift/trunk/lib/go/Make.deps
    thrift/trunk/lib/go/thrift/thttp_client.go
    thrift/trunk/lib/go/thrift/thttp_client_test.go
    thrift/trunk/lib/go/thrift/tnonblocking_socket.go
    thrift/trunk/lib/go/thrift/tprotocol_test.go
    thrift/trunk/lib/go/thrift/tsocket.go
    thrift/trunk/lib/go/thrift/ttransport.go
    thrift/trunk/lib/go/thrift/ttransport_test.go

Modified: thrift/trunk/compiler/cpp/src/generate/t_go_generator.cc
URL: http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_go_generator.cc?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_go_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_go_generator.cc Wed Jul 13 17:58:05 2011
@@ -220,6 +220,7 @@ class t_go_generator : public t_generato
   
   static std::string publicize(const std::string& value);
   static std::string privatize(const std::string& value);
+  static std::string variable_name_to_go_name(const std::string& value);
   static bool can_be_nil(t_type* value);
 
 };
@@ -254,6 +255,96 @@ std::string t_go_generator::privatize(co
   return value2;
 }
 
+std::string t_go_generator::variable_name_to_go_name(const std::string& value) {
+  if(value.size() <= 0) return value;
+  std::string value2(value);
+  std::transform(value2.begin(), value2.end(), value2.begin(), ::tolower);
+  switch(value[0]) {
+    case 'b':
+    case 'B':
+      if(value2 != "break") {
+        return value;
+      }
+      break;
+    case 'c':
+    case 'C':
+      if(value2 != "case" && value2 != "chan" && value2 != "const" && value2 != "continue") {
+        return value;
+      }
+      break;
+    case 'd':
+    case 'D':
+      if(value2 != "default" && value2 != "defer") {
+        return value;
+      }
+      break;
+    case 'e':
+    case 'E':
+      if(value2 != "else") {
+        return value;
+      }
+      break;
+    case 'f':
+    case 'F':
+      if(value2 != "fallthrough" && value2 != "for" && value2 != "func") {
+        return value;
+      }
+      break;
+    case 'g':
+    case 'G':
+      if(value2 != "go" && value2 != "goto") {
+        return value;
+      }
+      break;
+    case 'i':
+    case 'I':
+      if(value2 != "if" && value2 != "import" && value2 != "interface") {
+        return value;
+      }
+      break;
+    case 'm':
+    case 'M':
+      if(value2 != "map") {
+        return value;
+      }
+      break;
+    case 'p':
+    case 'P':
+      if(value2 != "package") {
+        return value;
+      }
+      break;
+    case 'r':
+    case 'R':
+      if(value2 != "range" && value2 != "return") {
+        return value;
+      }
+      break;
+    case 's':
+    case 'S':
+      if(value2 != "select" && value2 != "struct" && value2 != "switch") {
+        return value;
+      }
+      break;
+    case 't':
+    case 'T':
+      if(value2 != "type") {
+        return value;
+      }
+      break;
+    case 'v':
+    case 'V':
+      if(value2 != "var") {
+        return value;
+      }
+      break;
+    default:
+      return value;
+  }
+  return value2 + "_a1";
+}
+
+
 /**
  * Prepares for file generation by opening up the necessary file output
  * streams.
@@ -726,7 +817,7 @@ void t_go_generator::generate_go_struct_
       }
       t_type* fieldType = (*m_iter)->get_type();
       string goType(type_to_go_type(fieldType));
-      indent(out) << publicize((*m_iter)->get_name()) << " " 
+      indent(out) << publicize(variable_name_to_go_name((*m_iter)->get_name())) << " " 
                   << goType << " \"" << escape_string((*m_iter)->get_name())
                   << "\"; // " << sorted_keys_pos
                   << endl;
@@ -832,7 +923,7 @@ void t_go_generator::generate_go_struct_
     for(m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       t_type* orig_type = (*m_iter)->get_type();
       t_type* type = get_true_type(orig_type);
-      string field_name(publicize((*m_iter)->get_name()));
+      string field_name(publicize(variable_name_to_go_name((*m_iter)->get_name())));
       if(type->is_base_type() || type->is_enum()) {
         if(type->is_bool()) {
           out <<
@@ -870,7 +961,7 @@ void t_go_generator::generate_go_struct_
     indent() << "  default: return nil" << endl;
   indent_up();
   for(m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
-    string field_name(publicize((*m_iter)->get_name()));
+    string field_name(publicize(variable_name_to_go_name((*m_iter)->get_name())));
     out <<
       indent() << "case " << (*m_iter)->get_key() << ": return p." << field_name << endl;
   }
@@ -972,16 +1063,15 @@ void t_go_generator::generate_go_struct_
   // In the default case we skip the field
   if (first) {
     out <<
-      indent() << "if {" << endl;
+      indent() << "err = iprot.Skip(fieldTypeId)" << endl <<
+      indent() << "if err != nil { return thrift.NewTProtocolExceptionReadField(int(fieldId), fieldName, p.ThriftName(), err); }" << endl;
   } else {
     out <<
-      indent() << "} else {" << endl;
+      indent() << "} else {" << endl <<
+      indent() << "  err = iprot.Skip(fieldTypeId)" << endl <<
+      indent() << "  if err != nil { return thrift.NewTProtocolExceptionReadField(int(fieldId), fieldName, p.ThriftName(), err); }" << endl <<
+      indent() << "}" << endl;
   }
-  out <<
-    indent() << "  err = iprot.Skip(fieldTypeId)" << endl <<
-    indent() << "  if err != nil { return thrift.NewTProtocolExceptionReadField(int(fieldId), fieldName, p.ThriftName(), err); }" << endl <<
-    indent() << "}" << endl;
-
   // Read field end marker
   out <<
     indent() << "err = iprot.ReadFieldEnd()" << endl <<
@@ -1044,7 +1134,7 @@ void t_go_generator::generate_go_struct_
       fieldId = (*fr_iter)->get_key();
       if(can_be_nil((*fr_iter)->get_type()) && fieldId != 0) {
         out <<
-          indent() << "case p." << publicize(field_name) << " != nil:" << endl <<
+          indent() << "case p." << publicize(variable_name_to_go_name(field_name)) << " != nil:" << endl <<
           indent() << "  if err = p.WriteField" << fieldId << "(oprot); err != nil {" << endl <<
           indent() << "    return err" << endl <<
           indent() << "  }" << endl;
@@ -1091,7 +1181,7 @@ void t_go_generator::generate_go_struct_
     // Write field header
     if (can_be_nil((*f_iter)->get_type())) {
       out <<
-        indent() << "if p." << publicize(field_name) << " != nil {" << endl;
+        indent() << "if p." << publicize(variable_name_to_go_name(field_name)) << " != nil {" << endl;
       indent_up();
     }
     out <<
@@ -1377,7 +1467,7 @@ void t_go_generator::generate_service_cl
       } else {
         f_service_ << ", ";
       }
-      f_service_ << (*fld_iter)->get_name();
+      f_service_ << variable_name_to_go_name((*fld_iter)->get_name());
     }
     f_service_ << ")" << endl <<
       indent() << "if err != nil { return }" << endl;
@@ -1413,7 +1503,7 @@ void t_go_generator::generate_service_cl
     
     for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
       f_service_ <<
-        indent() << args << "." << publicize((*fld_iter)->get_name()) << " = " << (*fld_iter)->get_name() << endl;
+        indent() << args << "." << publicize(variable_name_to_go_name((*fld_iter)->get_name())) << " = " << variable_name_to_go_name((*fld_iter)->get_name()) << endl;
     }
     
     // Write to the stream
@@ -1607,7 +1697,7 @@ void t_go_generator::generate_service_re
     indent() << "if useHttp {" << endl <<
     indent() << "  trans, err = thrift.NewTHttpClient(url.Raw)" << endl <<
     indent() << "} else {" << endl <<
-    indent() << "  addr, err := net.ResolveTCPAddr(fmt.Sprint(host, \":\", port))" << endl <<
+    indent() << "  addr, err := net.ResolveTCPAddr(\"tcp\", fmt.Sprint(host, \":\", port))" << endl <<
     indent() << "  if err != nil {" << endl <<
     indent() << "    fmt.Fprint(os.Stderr, \"Error resolving address\", err.String())" << endl <<
     indent() << "    os.Exit(1)" << endl <<
@@ -2035,7 +2125,7 @@ void t_go_generator::generate_process_fu
     const vector<t_field*>& fields = exceptions->get_members();
     vector<t_field*>::const_iterator f_iter;
     for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
-      f_service_ << "result." << publicize((*f_iter)->get_name()) << ", ";
+      f_service_ << "result." << publicize(variable_name_to_go_name((*f_iter)->get_name())) << ", ";
     }
   }
   
@@ -2054,7 +2144,7 @@ void t_go_generator::generate_process_fu
     } else {
       f_service_ << ", ";
     }
-    f_service_ << "args." << publicize((*f_iter)->get_name());
+    f_service_ << "args." << publicize(variable_name_to_go_name((*f_iter)->get_name()));
   }
   f_service_ << "); err != nil {" << endl <<
     indent() << "  x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, \"Internal error processing " << escape_string(tfunction->get_name()) << ": \" + err.String())" << endl <<
@@ -2148,7 +2238,7 @@ void t_go_generator::generate_deserializ
                                                 bool coerceData) {
   t_type* orig_type = tfield->get_type();
   t_type* type = get_true_type(orig_type);
-  string name(prefix + publicize(tfield->get_name()));
+  string name(prefix + publicize(variable_name_to_go_name(tfield->get_name())));
 
   if (type->is_void()) {
     throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " + name;
@@ -2420,7 +2510,7 @@ void t_go_generator::generate_serialize_
                                                string prefix,
                                                string err) {
   t_type* type = get_true_type(tfield->get_type());
-  string name(prefix + publicize(tfield->get_name()));
+  string name(prefix + publicize(variable_name_to_go_name(tfield->get_name())));
 
   // Do nothing for void types
   if (type->is_void()) {
@@ -2483,7 +2573,7 @@ void t_go_generator::generate_serialize_
                         << ", \"" << escape_string(tfield->get_name())
                         << "\", " << structName << ", " << err << "); }\n";
   } else {
-    throw "INVALID TYPE IN generate_serialize_field '" + type->get_name() + "' for field '" + prefix + publicize(tfield->get_name()) + "'";
+    throw "INVALID TYPE IN generate_serialize_field '" + type->get_name() + "' for field '" + name + "'";
   }
 }
 
@@ -2677,7 +2767,7 @@ void t_go_generator::generate_go_docstri
     vector<t_field*>::const_iterator p_iter;
     for (p_iter = fields.begin(); p_iter != fields.end(); ++p_iter) {
       t_field* p = *p_iter;
-      ss << " - " << publicize(p->get_name());
+      ss << " - " << publicize(variable_name_to_go_name(p->get_name()));
       if (p->has_doc()) {
         ss << ": " << p->get_doc();
       } else {
@@ -2802,7 +2892,7 @@ string t_go_generator::argument_list(t_s
     } else {
       result += ", ";
     }
-    result += (*f_iter)->get_name() + " " + type_to_go_type((*f_iter)->get_type());
+    result += variable_name_to_go_name((*f_iter)->get_name()) + " " + type_to_go_type((*f_iter)->get_type());
   }
   return result;
 }

Modified: thrift/trunk/lib/go/Make.deps
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/Make.deps?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/Make.deps (original)
+++ thrift/trunk/lib/go/Make.deps Wed Jul 13 17:58:05 2011
@@ -6,8 +6,10 @@ big.install: ${GOROOT}/pkg/${GOOS}_${GOA
 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/ring.install: ${GOROOT}/pkg/${
 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/subtle.install: ${GOROOT}/pkg/${G
 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/printer.install: ${GOROOT}/pkg/${GOOS
 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 @@ net/textproto.install: ${GOROOT}/pkg/${G
 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 @@ sort.install: ${GOROOT}/pkg/${GOOS}_${GO
 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 @@ xml.install: ${GOROOT}/pkg/${GOOS}_${GOA
 ../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

Modified: thrift/trunk/lib/go/thrift/thttp_client.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/thttp_client.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/thttp_client.go (original)
+++ thrift/trunk/lib/go/thrift/thttp_client.go Wed Jul 13 17:58:05 2011
@@ -23,6 +23,7 @@ import (
   "bytes"
   "http"
   "os"
+  "strconv"
 )
 
 
@@ -69,11 +70,11 @@ func NewTHttpPostClientTransportFactory(
 
 
 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 @@ func (p *THttpClient) Flush() os.Error {
   }
   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

Modified: thrift/trunk/lib/go/thrift/thttp_client_test.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/thttp_client_test.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/thttp_client_test.go (original)
+++ thrift/trunk/lib/go/thrift/thttp_client_test.go Wed Jul 13 17:58:05 2011
@@ -22,20 +22,13 @@ package thrift_test
 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, err := net.Listen(addr.Network(), addr.String())
-  if err != nil {
-    t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
+  l, addr := HttpClientSetupForTest(t)
+  if l != nil {
+    defer l.Close()
   }
-  go http.Serve(l, &HTTPEchoServer{})
   trans, err := NewTHttpPostClient("http://" + addr.String())
   if err != nil {
     l.Close()

Modified: thrift/trunk/lib/go/thrift/tnonblocking_socket.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/tnonblocking_socket.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/tnonblocking_socket.go (original)
+++ thrift/trunk/lib/go/thrift/tnonblocking_socket.go Wed Jul 13 17:58:05 2011
@@ -108,7 +108,7 @@ func (p *TNonblockingSocket) Open() os.E
   }
 
   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())
   }

Modified: thrift/trunk/lib/go/thrift/tprotocol_test.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/tprotocol_test.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/tprotocol_test.go (original)
+++ thrift/trunk/lib/go/thrift/tprotocol_test.go Wed Jul 13 17:58:05 2011
@@ -25,7 +25,7 @@ import (
   "http"
   "math"
   "net"
-  "io"
+  "io/ioutil"
   "os"
   "bytes"
   "fmt"
@@ -64,18 +64,26 @@ func init() {
 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 HttpClientSetupForTest(t *testing.T
 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 @@ func ReadWriteProtocolTest(t *testing.T,
   //  trans.Close()
   //}
 
-  l.Close()
 }
 
 func ReadWriteBool(t *testing.T, p TProtocol, trans TTransport) {

Modified: thrift/trunk/lib/go/thrift/tsocket.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/tsocket.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/tsocket.go (original)
+++ thrift/trunk/lib/go/thrift/tsocket.go Wed Jul 13 17:58:05 2011
@@ -134,7 +134,7 @@ func (p *TSocket) Open() os.Error {
     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())
   }

Modified: thrift/trunk/lib/go/thrift/ttransport.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/ttransport.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/ttransport.go (original)
+++ thrift/trunk/lib/go/thrift/ttransport.go Wed Jul 13 17:58:05 2011
@@ -22,6 +22,7 @@ package thrift
 import (
   "os"
   "log"
+  "strconv"
 )
 
 type Flusher interface {
@@ -162,7 +163,7 @@ func ReadAllTransport(p TTransport, buf 
     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
     }

Modified: thrift/trunk/lib/go/thrift/ttransport_test.go
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/go/thrift/ttransport_test.go?rev=1146167&r1=1146166&r2=1146167&view=diff
==============================================================================
--- thrift/trunk/lib/go/thrift/ttransport_test.go (original)
+++ thrift/trunk/lib/go/thrift/ttransport_test.go Wed Jul 13 17:58:05 2011
@@ -124,7 +124,7 @@ func FindAvailableTCPServerPort(startPor
     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")