...
1# Thrift
2
3[Thrift](https://thrift.apache.org/) is a large IDL and transport package from Apache, popularized by Facebook.
4Thrift is well-supported in Go kit, for organizations that already have significant Thrift investment.
5And using Thrift with Go kit is very simple.
6
7First, define your service in the Thrift IDL.
8The [Thrift IDL documentation](https://thrift.apache.org/docs/idl) provides more details.
9See [addsvc.thrift](https://github.com/go-kit/examples/blob/master/addsvc/thrift/addsvc.thrift) for an example.
10Make sure the Thrift definition matches your service's Go kit (interface) definition.
11
12Next, [download Thrift](https://thrift.apache.org/download) and [install the compiler](https://thrift.apache.org/docs/install/).
13On a Mac, you may be able to `brew install thrift`.
14
15Then, compile your service definition, from .thrift to .go.
16You'll probably want to specify the package_prefix option to the --gen go flag.
17See [THRIFT-3021](https://issues.apache.org/jira/browse/THRIFT-3021) for more details.
18
19```
20thrift -r --gen go:package_prefix=github.com/my-org/my-repo/thrift/gen-go/ add.thrift
21```
22
23Finally, write a tiny binding from your service definition to the Thrift definition.
24It's a straightforward conversion from one domain to the other.
25See [thrift.go](https://github.com/go-kit/examples/blob/master/addsvc/pkg/addtransport/thrift.go) for an example.
26
27That's it!
28The Thrift binding can be bound to a listener and serve normal Thrift requests.
29And within your service, you can use standard Go kit components and idioms.
30Unfortunately, setting up a Thrift listener is rather laborious and nonidiomatic in Go.
31Fortunately, [addsvc](https://github.com/go-kit/examples/tree/master/addsvc) is a complete working example with Thrift support.
32And remember: Go kit services can support multiple transports simultaneously.
View as plain text