• Stars
    star
    385
  • Rank 110,785 (Top 3 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created about 12 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A native Thrift package for Go

Thrift Package for Go

Build Status

API Documentation: http://godoc.org/github.com/samuel/go-thrift

License

3-clause BSD. See LICENSE file.

Overview

Thrift is an IDL that can be used to generate RPC client and server bindings for a variety of languages. This package includes client and server codecs, serialization, and code generation for Go. It tries to be a more natural mapping to the language compared to other implementations. For instance, Go already has the idea of a thrift transport in the ReadWriteCloser interfaces.

Types

Most types map directly to the native Go types, but there are some quirks and limitations.

  • Go supports a more limited set of types for map keys than Thrift

  • To use a set define the field as []type and provide a tag of "set":

      StringSet []string `thrift:"1,set"`
    
  • []byte get encoded/decoded as a string because the Thrift binary type is the same as string on the wire.

RPC

The standard Go net/rpc package is used to provide RPC. Although, one incompatibility is the net/rpc's use of ServiceName.Method for naming RPC methods. To get around this the Thrift ServerCodec prefixes method names with "Thrift".

Transport

There are no specific transport "classes" as there are in most Thrift libraries. Instead, the standard io.ReadWriteCloser is used as the interface. If the value also implements the thrift.Flusher interface then Flush() error is called after protocol.WriteMessageEnd.

Framed transport is supported by wrapping a value implementing io.ReadWriteCloser with thrift.NewFramedReadWriteCloser(value)

One-way requests

Client

One-way request support needs to be enabled on the RPC codec explicitly. The reason they're not allowed by default is because the Go RPC package doesn't actually support one-way requests. To get around this requires a rather janky hack of using channels to track pending requests in the codec and faking responses.

Server

One-way requests aren't yet implemented on the server side.

Parser & Code Generator

The "parser" subdirectory contains a Thrift IDL parser, and "generator" contains a Go code generator. It could be extended to include other languages.

How to use the generator:

$ go install github.com/samuel/go-thrift/generator

$ generator --help
Usage of generator:
  -go.binarystring
        Always use string for binary instead of []byte
  -go.importprefix string
        Prefix for Thrift-generated go package imports
  -go.json.enumnum
        For JSON marshal enums by number instead of name
  -go.pointers
        Make all fields pointers
  -go.signedbytes
        Interpret Thrift byte as Go signed int8 type

$ generator cassandra.thrift $GOPATH/src/

TODO

  • default values
  • oneway requests on the server

More Repositories

1

go-zookeeper

Native ZooKeeper client for Go. This project is no longer maintained. Please use https://github.com/go-zookeeper/zk instead.
Go
1,640
star
2

python-munin

Python framework for building Munin plugins (also includes some plugins prebuilt).
Python
292
star
3

python-ping

Pure Python version of ICMP ping
Python
221
star
4

kokki

System configuration management framework influenced by Chef
Python
192
star
5

go-opencl

OpenCL bindings for Go
Go
143
star
6

squawk

SQL Query Tool for Static Files
Python
103
star
7

python-bert

BERT serialization library for Python
Python
81
star
8

python-gearman

(maintenance transfered to http://github.com/Yelp/python-gearman) Gearman library for Python.
Python
70
star
9

python-erlastic

Erlang binary term codec and port interface. Modeled after Erlectricity.
Python
49
star
10

go-dsp

DSP and Software Defined Radio (SDR) package for Go
Go
46
star
11

go-ldap

LDAP client and server for Go
Go
42
star
12

go-metrics

Metrics library and aggregation daemon for Go
Go
32
star
13

go-socks

SOCKS5 proxy library for Go
Go
30
star
14

lua-quadtree

Quadtree library for Lua
Lua
26
star
15

go-hackrf

HackRF SDR interface library for Go
Go
22
star
16

go-gettext

Native gettext package for Go
Go
21
star
17

python-scrubber

A whitelisting HTML sanitizer for Python
Python
21
star
18

go-spacecurves

Space filling curves (Hilbert, Morton / Z-order)
Go
16
star
19

go-rtlsdr

RTL-SDR Package for Go
Go
13
star
20

go-pcx

PCX image encoder and decoder for Go
Go
11
star
21

erlang-gearman

Gearman library for Erlang.
Erlang
10
star
22

go-classifier

Document classifier (bayesian) package for Go
Go
9
star
23

go-remez

Parks-McClellan (aka Remez) algorithm
Go
7
star
24

go-cache

In process cache (LRU, ...) package for Go
Go
7
star
25

go-parser

Parsing package for Go
Go
5
star
26

go-emu

Emulators written in Go
Go
5
star
27

go-librato

Go library for Librato Metrics
Go
5
star
28

go-imagex

Image extensions for Go
Go
5
star
29

go-quicklook

Framework for building macOS QuickLook plugins in Go
C
3
star
30

go-redis

Redis client for Go
Go
3
star
31

go-dtw

Dynamic Time Warping (DTW) package for Go
Go
3
star
32

go-astar

A* implementation in Go
Go
3
star
33

TI86-Forth

Forth interpreter for the TI-86 calculator I made back in 1996.
2
star
34

gentlemanjunkie.com

Gentleman Junkie the band
2
star
35

rfexplorer

Go library and tools to communicate with the RF Explorer handheld spectrum analyzer
Go
2
star
36

go-bbcode

BBCode renderer for Go
Go
2
star
37

go-pinboard

Pinboard API client for Go
Go
2
star
38

samuel.github.com

My Github homepage
1
star
39

go-accelerate

Go bindings for Apple's accelerate framework
Go
1
star
40

graphics-tutorial

JavaScript
1
star
41

BrinnoTLC100

OS X app to the configure the Brinno TLC100 time-lapse camera
Objective-C
1
star