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/compiler/cpp/src/generate/t_go_generator.cc b/compiler/cpp/src/generate/t_go_generator.cc
index f7bfe75..fe34bb7 100644
--- a/compiler/cpp/src/generate/t_go_generator.cc
+++ b/compiler/cpp/src/generate/t_go_generator.cc
@@ -220,6 +220,7 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
// 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 @@
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 @@
// 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 @@
} 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 @@
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 @@
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 @@
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 @@
} 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 @@
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 @@
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 @@
<< ", \"" << 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 @@
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 @@
} 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;
}
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")