State of Thrift support for Go 1.x ?

1,123 views
Skip to first unread message

Justin Israel

unread,
May 9, 2013, 11:40:32 PM5/9/13
to golan...@googlegroups.com
Can anyone confirm whether Thrift support for Go is officially up to date?
I was trying to get started with a new project, and was just testing out the thrift generator and it seemed to produce code that isn't valid for Go 1.x? Mainly a lot of  "err is shadowed during return" until it just failed.

I saw go-thrift, which comes with it's own generator, but it seems like you have to write your spec file in Go as opposed to the thrift spec? It didn't seems to want to parse my existing thrift spec file without a syntax error.

Then after search for Go 1.1 thrift support, I came across this:

Not sure if this is maintained, or just something that someone threw out there once, since it only has 2 commits.


Damian Gryski

unread,
May 10, 2013, 2:50:24 AM5/10/13
to golan...@googlegroups.com
There's also a pure Go thrft implementation at github.com/Samuel/go-thrift . Not sure how it compares to the others though.

Damian

buzzlight

unread,
May 10, 2013, 2:51:34 AM5/10/13
to golan...@googlegroups.com
I prefer this package 

the code generated by it is GO style, thrift-go is more like Java.
 


在 2013年5月10日星期五UTC+8上午11时40分32秒,Justin Israel写道:

Ingo Oeser

unread,
May 10, 2013, 12:33:42 PM5/10/13
to golan...@googlegroups.com
That one is an excellent implementation, which feels really like Go. It just misses default cases,
which are not recommended in such protocols anyway.

If your primary code base it Go and you just want to make it easy for others to connect, that pure Go one is highly recommended. 
You can use normal readers and writers with it and have no additional transport and buffering layers generated and added, which Go already has. 
It also needs nothing besides Go itself and generates Code which can be augmented with further struct tags

But if Go is just another use case you have to support and your main code base is PHP, Ruby, Java, Python and whatever, I would recommend to use the thrift compiler mentioned in other posts,
as it provides the same tooling for every language supported.

Justin Israel

unread,
May 11, 2013, 5:45:45 AM5/11/13
to golan...@googlegroups.com
Thanks for the info everyone! This is actually an attempt to use calls to an existing Java server with a thrift interface. 
It seemed to generate bindings that don't work too well.

1) It uses an import statement "github.com/apesternikov/thrift4go/lib/go/src/thrift" even though the merge install process creates it as "thrift", so I had to symlink the pkg
2) It didn't really like the fact that the project uses two different thrift files, with one importing the other. It created duplicate declarations for some stuff in the main file, and the other "common" thrift file had unused imports.
After I hand edited the main generated file to just paste in the lines from the other "common" generated file and removed the import for it, it was complaining a bunch about the fact that it uses a "type Guid string", and uses that Guid type as a string argument:

    RpcService.go:10337: cannot use p.Id (type Guid) as type string in function argument

Ideally I would just be able to generate the bindings the same way as the other project does for Java and python, and just have immediately functional bindings. Seems like what is being generated needs some hand editing so far  :-(

Justin Israel

unread,
Jul 11, 2013, 7:06:34 PM7/11/13
to golan...@googlegroups.com
Sorry to revive an older thread, but I am revisiting this problem again to try and see if I really can get Go thrift client bindings to work, for a few of our existing services. Can anyone offer some insight as to this type of error?

The thrift spec defines a type:
    typedef string Id

which generates the equivalent in the Go ttypes:
    type Id string

but produces a ton of errors in all of the function calls that expect a string, but are passed an Id type:
    cannot use p.Id (type Id) as type string in function argument

notmik...@gmail.com

unread,
Jul 12, 2013, 1:29:47 PM7/12/13
to golan...@googlegroups.com
I'm not familiar with that error, but just wanted to say that the official thrift Go support has been recently patched (pulling in pomacks work and some others). I'm using the dev version of thrift from git with Go1.1.1 and not having any issues.

See https://issues.apache.org/jira/browse/THRIFT-2012

Justin Israel

unread,
Jul 13, 2013, 10:52:43 PM7/13/13
to golan...@googlegroups.com, notmik...@gmail.com
Did you have to update any existing service implementations in your code? I grabbed the git repo and built thrift-1.0.0dev. It generated Go bindings for my project fine and compiled them file as well. But when building the existing project (from thrift 0.9.0) again, its complaining about the thrift service implementations as if stuff has changed to break 0.9.0

Justin Israel

unread,
Jul 13, 2013, 11:50:49 PM7/13/13
to golan...@googlegroups.com, notmik...@gmail.com
I managed to get something working, but only by keeping my existing projects code using thrift 0.9.0 generated bindings so that they would compile, and then used the thrift 1.0.0 generator to specifically generate the Go bindings. 
Reply all
Reply to author
Forward
0 new messages