thrift

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package thrift implements Thrift encoding support for YARPC.

To use this package, you must install ThriftRW 0.2.0 or newer.

go get go.uber.org/thriftrw

You must also install the ThriftRW plugin for YARPC.

go get go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc

To generate YARPC compatible code from a Thrift file, use the command,

thriftrw --plugin yarpc myservice.thrift

In addition to generating code for types specified in your THrift file, this will generate two packages for each service in the file: a client package and a server package.

myservice
 |- yarpc
     |- myserviceclient
     |- myserviceserver

The client package allows sending requests through a YARPC channel.

client := myserviceclient.New(dispatcher.Channel("myservice"))

The server package facilitates registration of service implementations with a YARPC dispatcher.

handler := myHandler{}
thrift.Register(dispatcher, myserviceserver.New(handler))

Index

Constants

View Source
const Encoding transport.Encoding = "thrift"

Encoding is the name of this encoding.

Variables

View Source
var DisableEnvelopingForTransport transport.Options

DisableEnvelopingForTransport allows a transport to disable Thrift request and response enveloping.

Use this from a transport implementation that wishes to disable Thrift enveloping.

func (myOutbound) Options() transport.Options {
	return otherOptions.Merge(thrift.DisableEnvelopingForTransport)
}

Functions

func Register

func Register(registry transport.Registry, service Service, opts ...RegisterOption)

Register registers the handlers for the methods of the given service with the given Registry.

Types

type Client

type Client interface {
	// Call the given Thrift method.
	Call(ctx context.Context, reqMeta yarpc.CallReqMeta, reqBody envelope.Enveloper) (wire.Value, yarpc.CallResMeta, error)
}

Client is a generic Thrift client. It speaks in raw Thrift payloads.

Users should use the client generated by the code generator rather than using this directly.

func New

func New(c Config, opts ...ClientOption) Client

New creates a new Thrift client.

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption customizes the behavior of a Thrift client.

var Multiplexed ClientOption = multiplexedOption{}

Multiplexed is an option that specifies that requests from a client should use Thrift multiplexing. This option should be used if the remote server is using Thrift's TMultiplexedProtocol. It includes the name of the service in the envelope name for all outbound requests.

Specify this option when constructing the Thrift client.

client := myserviceclient.New(channel, thrift.Multiplexed)

type Config

type Config struct {
	// Name of the Thrift service. This is the name used in the Thrift file
	// with the 'service' keyword.
	Service string

	// Channel through which requests will be sent. Required.
	Channel transport.Channel

	// Thrift encoding protocol. Defaults to Binary if nil.
	Protocol protocol.Protocol
}

Config contains the configuration for the Client.

type Handler

type Handler interface {
	Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body wire.Value) (Response, error)
}

Handler represents a Thrift request handler. It speaks in raw Thrift payloads.

Users should use the server package generated by the code generator rather than using this directly.

type HandlerFunc

type HandlerFunc func(context.Context, yarpc.ReqMeta, wire.Value) (Response, error)

HandlerFunc is a convenience type alias for functions that act as Handlers.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body wire.Value) (Response, error)

Handle forwards the request to the underlying function.

type Option

type Option interface {
	ClientOption
	RegisterOption
}

Option unifies options that apply to both, Thrift clients and handlers.

var DisableEnveloping Option = disableEnvelopingOption{}

DisableEnveloping is an option that disables enveloping of Thrift requests and responses.

It may be specified on the client side when the client is constructed.

client := myserviceclient.New(channel, thrift.DisableEnveloping)

It may be specified on the server side when the handler is registered.

thrift.Register(dispatch, myserviceserver.New(handler), thrift.DisableEnveloping)

type RegisterOption

type RegisterOption interface {
	// contains filtered or unexported methods
}

RegisterOption customizes the behavior of a Thrift handler during registration.

type Response

type Response struct {
	Body envelope.Enveloper
	Meta yarpc.ResMeta

	IsApplicationError bool
}

Response contains the raw response from a generated Thrift handler.

type Service

type Service interface {
	// Name of the Thrift service.
	Name() string

	// Protocol to use for requests and responses of this service.
	Protocol() protocol.Protocol

	// Map of method name to Handler for all methods of this service.
	Handlers() map[string]Handler
}

Service represents a Thrift service implementation.

Directories

Path Synopsis
thriftrw-plugin-yarpc implements a plugin for ThriftRW that generates code compatible with YARPC.
thriftrw-plugin-yarpc implements a plugin for ThriftRW that generates code compatible with YARPC.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL