Coder Social home page Coder Social logo

go-thrift's Introduction

Thrift Package for Go

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

Overview

So why another thrift package? While the existing one (thrift4go) works well, my philosophy is that interfaces should match the language. Most Thrift libraries try to match the API of the original which makes them awkward to use in other languages.

As an example, Go already has the idea of a thrift transport in the ReadWriteCloser interfaces.

Another design decision was to keep the generated code as terse as possible. The generator only creates a struct and the encoding/decoding is done through reflection. Annotations are used to set thrift ID for a field and options such as 'required'.

Example struct:

type User struct {
    Id        int64    `thrift:"1,required"`
    Name      string   `thrift:"2"`
    PostCount int32    `thrift:"3,keepempty"`
    Flags     []string `thrift:"4"`
    SomeSet   []string `thrift:"5,set"`
}

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"`
    
  • Unsigned types aren't supported. Thrift only has signed types. Could encode/decode unsigned types as their signed counterparts, but I decided against that for now.

  • []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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.