Documentation ¶
Overview ¶
Package thrift implements Thrift encoding support for YARPC.
To use this package, you must install ThriftRW 1.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 |- myserviceclient |- myserviceserver
The client package allows sending requests through a YARPC dispatcher.
client := myserviceclient.New(dispatcher.ClientConfig("myservice"))
The server package facilitates registration of service implementations with a YARPC dispatcher.
handler := myHandler{} dispatcher.Register(myserviceserver.New(handler))
Index ¶
- Constants
- func BuildProcedures(s Service, opts ...RegisterOption) []transport.Procedure
- func Register(r transport.RouteTable, rs []transport.Procedure)deprecated
- type Client
- type ClientOption
- type Config
- type HandlerSpec
- type Method
- type OnewayHandler
- type Option
- type RegisterOption
- type Response
- type Service
- type UnaryHandler
Constants ¶
const Encoding transport.Encoding = "thrift"
Encoding is the name of this encoding.
Variables ¶
This section is empty.
Functions ¶
func BuildProcedures ¶ added in v1.0.0
func BuildProcedures(s Service, opts ...RegisterOption) []transport.Procedure
BuildProcedures builds a list of Procedures from a Thrift service specification.
func Register
deprecated
func Register(r transport.RouteTable, rs []transport.Procedure)
Register calls the RouteTable's Register method.
This function exists for backwards compatibility only. It will be removed in a future version.
Deprecated: Use the RouteTable's Register method directly.
Types ¶
type Client ¶
type Client interface { // Call the given Thrift method. Call(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (wire.Value, error) CallOneway(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (transport.Ack, 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.
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(clientConfig, 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 // ClientConfig through which requests will be sent. Required. ClientConfig transport.ClientConfig }
Config contains the configuration for the Client.
type HandlerSpec ¶ added in v1.0.0
type HandlerSpec struct { Type transport.Type Unary UnaryHandler Oneway OnewayHandler }
HandlerSpec represents the handler behind a Thrift service method.
type Method ¶ added in v1.0.0
type Method struct { // Name of the method itself. Name string // The handler to call. HandlerSpec HandlerSpec // Snippet of Go code representing the function definition of the handler. // This is useful for introspection. Signature string }
Method represents a Thrift service method.
type OnewayHandler ¶ added in v0.4.0
OnewayHandler is a convenience type alias for functions that act as OnewayHandlers.
type Option ¶
type Option interface { ClientOption RegisterOption }
Option unifies options that apply to both, Thrift clients and handlers.
var Enveloped Option = envelopedOption{}
Enveloped is an option that specifies that Thrift requests and responses should be enveloped. It defaults to false.
It may be specified on the client side when the client is constructed.
client := myserviceclient.New(clientConfig, thrift.Enveloped)
It may be specified on the server side when the handler is registered.
dispatcher.Register(myserviceserver.New(handler, thrift.Enveloped))
Note that you will need to enable enveloping to communicate with Apache Thrift HTTP servers.
func Protocol ¶ added in v0.4.0
Protocol is an option that specifies which Thrift Protocol servers and clients should use. It may be specified on the client side when the client is constructed,
client := myserviceclient.New(clientConfig, thrift.Protocol(protocol.Binary))
It may be specified on the server side when the handler is registered.
dispatcher.Register(myserviceserver.New(handler, thrift.Protocol(protocol.Binary)))
It defaults to the Binary protocol.
type RegisterOption ¶
type RegisterOption interface {
// contains filtered or unexported methods
}
RegisterOption customizes the behavior of a Thrift handler during registration.
Source Files ¶
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. |