/
doc.go
131 lines (130 loc) · 5.26 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// 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 the following packages for each service in the file: a
// client package, a server package, a test package, and an UberFx module.
//
// myservice
// |- myserviceclient
// |- myserviceserver
// |- myservicefx
// |- myservicetest
//
// 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))
//
// The test package provides a gomock-compatible mock client for the service.
//
// mockCtrl := gomock.NewController(t)
// client := myservicetest.NewMockClient(mockCtrl)
// client.EXPECT().Hello(request).Return(response, nil)
//
// The Fx package provides an UberFx-compatible constructor for service
// clients. This may be used with Provide to make service clients available in
// the container.
//
// fx.Provide(myservicefx.Client("myservice"))
//
// The Fx package also provides an UberFx-compatible constructor for
// registering service procedures. This expects an instance of the service
// interface to be available in the container and provides the list of
// procedures resulting from that to the "yarpcfx" value group.
//
// fx.Provide(
// myservicefx.Server(),
// NewMyServiceHandler, // func(...) myserviceserver.Interface
// )
//
// Automatically Building Clients
//
// All clients generated by the YARPC ThriftRW plugin are compatible with
// YARPC's yarpc.InjectClients function.
//
// var handler struct{ Client keyvalueclient.Interface `service:"keyvalue"` }
// yarpc.Injectclients(dispatcher, &handler)
//
// These clients may further be customized by providing a "thrift" tag. The
// following options may be provided on the tag using a comma-separated list.
//
// enveloped: Requests and responses will be wrapped inside a standard
// Apache Thrift envelope. This flag is needed to call existing
// Apache Thrift services with clients generated by YARPC.
// Equivalent to passing thrift.Enveloped.
// multiplexed: Requests are being sent to an Apache Thrift server which has
// multiplexing enabled. Equivalent to passing
// thrift.Multiplexed. This option has no effect if enveloped
// was not set.
//
// For example,
//
// type handler struct {
// Client keyvalueclient.Interface `service:"keyvalue" thrift:"multiplexed,enveloped"`
// }
//
// var h handler
// yarpc.Injectclients(dispatcher, &h)
//
// Calling Existing Apache Thrift Services
//
// You can call existing Apache Thrift services with YARPC by passing in the
// thrift.Enveloped option when constructing the corresponding clients.
//
// client := myserviceclient.New(dispatcher.ClientConfig("myservice"), thrift.Enveloped)
//
// With yarpc.InjectClients, you can pass the tag `thrift:"enveloped"` to
// enable this option on automatically instantiated clients.
//
// type handler struct {
// Client myserviceclient.Interface `service:"myservice" thrift:"enveloped"`
// }
//
// var h handler
// yarpc.InjectClients(dispatcher, &h)
//
// Automatically Sanitizing TChannel Contexts
//
// Contexts created with `tchannel.ContextWithHeaders` are incompatible with YARPC clients generated from Thrift.
// Using such a context will cause a YARPC client to error on any call. Using the `sanitize-tchannel` flag will
// generate a YARPC client such that all TChannel headers from any context supplied are removed before making a YARPC call.
// The option can be used like so:
//
// thriftrw --plugin "yarpc --sanitize-tchannel" myservice.thrift
package thrift