21
21
package interceptor
22
22
23
23
import (
24
- "go.uber.org/yarpc/api/middleware"
24
+ "context"
25
+
26
+ "go.uber.org/yarpc/api/transport"
25
27
)
26
28
27
29
type (
30
+ // UnaryOutboundChain defines the interface for a chain of unary outbound requests.
31
+ // It provides methods to invoke the next outbound in the chain with the given context
32
+ // and request, and to retrieve the outbound component of the chain.
33
+ //
34
+ // Next: Executes the next outbound request in the chain with the provided context and request,
35
+ // returning the response and any error encountered during the process.
36
+ // Outbound: Retrieves the outbound component of the chain, allowing for further inspection or manipulation.
37
+ UnaryOutboundChain interface {
38
+ Next (ctx context.Context , request * transport.Request ) (* transport.Response , error )
39
+ Outbound () transport.Outbound
40
+ }
41
+
42
+ // OnewayOutboundChain defines the interface for a chain of one-way outbound requests.
43
+ // It provides methods to invoke the next outbound in the chain with the given context
44
+ // and request, and to retrieve the outbound component of the chain.
45
+ //
46
+ // Next: Executes the next one-way outbound request in the chain with the provided context and request,
47
+ // returning an acknowledgment and any error encountered during the process.
48
+ // Outbound: Retrieves the outbound component of the chain, allowing for further inspection or manipulation.
49
+ OnewayOutboundChain interface {
50
+ Next (ctx context.Context , request * transport.Request ) (transport.Ack , error )
51
+ Outbound () transport.Outbound
52
+ }
53
+
54
+ // StreamOutboundChain defines the interface for a chain of streaming outbound requests.
55
+ // It provides methods to invoke the next outbound in the chain with the given context
56
+ // and request, and to retrieve the outbound component of the chain.
57
+ //
58
+ // Next: Executes the next streaming outbound request in the chain with the provided context and request,
59
+ // returning a client stream and any error encountered during the process.
60
+ // Outbound: Retrieves the outbound component of the chain, allowing for further inspection or manipulation.
61
+ StreamOutboundChain interface {
62
+ Next (ctx context.Context , request * transport.StreamRequest ) (* transport.ClientStream , error )
63
+ Outbound () transport.Outbound
64
+ }
65
+
28
66
// UnaryOutbound defines transport interceptor for `UnaryOutbound`s.
29
67
//
30
68
// UnaryOutbound interceptor MAY do zero or more of the following: change the
36
74
//
37
75
// UnaryOutbound interceptor is re-used across requests and MAY be called
38
76
// multiple times on the same request.
39
- UnaryOutbound = middleware.UnaryOutbound
77
+ UnaryOutbound interface {
78
+ Call (ctx context.Context , request * transport.Request , out UnaryOutboundChain ) (* transport.Response , error )
79
+ }
40
80
41
81
// OnewayOutbound defines transport interceptor for `OnewayOutbound`s.
42
82
//
49
89
//
50
90
// OnewayOutbound interceptor is re-used across requests and MAY be called
51
91
// multiple times on the same request.
52
- OnewayOutbound = middleware.OnewayOutbound
92
+ OnewayOutbound interface {
93
+ CallOneway (ctx context.Context , request * transport.Request , out OnewayOutboundChain ) (transport.Ack , error )
94
+ }
53
95
54
96
// StreamOutbound defines transport interceptor for `StreamOutbound`s.
55
97
//
@@ -62,5 +104,109 @@ type (
62
104
//
63
105
// StreamOutbound interceptors is re-used across requests and MAY be called
64
106
// multiple times on the same request.
65
- StreamOutbound = middleware.StreamOutbound
107
+ StreamOutbound interface {
108
+ CallStream (ctx context.Context , req * transport.StreamRequest , out StreamOutboundChain ) (* transport.ClientStream , error )
109
+ }
66
110
)
111
+
112
+ // DirectUnaryOutbound is a transport that knows how to send unary requests for procedure
113
+ // calls.
114
+ type DirectUnaryOutbound interface {
115
+ transport.Outbound
116
+
117
+ // DirectCall is called without interceptor.
118
+ DirectCall (ctx context.Context , request * transport.Request ) (* transport.Response , error )
119
+ }
120
+
121
+ // DirectOnewayOutbound defines a transport outbound for oneway requests
122
+ // that does not involve any interceptors.
123
+ type DirectOnewayOutbound interface {
124
+ transport.Outbound
125
+
126
+ // DirectCallOneway is called without interceptor.
127
+ DirectCallOneway (ctx context.Context , request * transport.Request ) (transport.Ack , error )
128
+ }
129
+
130
+ // DirectStreamOutbound defines a transport outbound for streaming requests
131
+ // that does not involve any interceptors.
132
+ type DirectStreamOutbound interface {
133
+ transport.Outbound
134
+
135
+ // DirectCallStream is called without interceptor.
136
+ DirectCallStream (ctx context.Context , req * transport.StreamRequest ) (* transport.ClientStream , error )
137
+ }
138
+
139
+ type nopUnaryOutbound struct {}
140
+
141
+ func (nopUnaryOutbound ) Call (ctx context.Context , request * transport.Request , out UnaryOutboundChain ) (* transport.Response , error ) {
142
+ return out .Next (ctx , request )
143
+ }
144
+
145
+ // NopUnaryOutbound is a unary outbound middleware that does not do
146
+ // anything special. It simply calls the underlying UnaryOutbound.
147
+ var NopUnaryOutbound UnaryOutbound = nopUnaryOutbound {}
148
+
149
+ type nopOnewayOutbound struct {}
150
+
151
+ func (nopOnewayOutbound ) CallOneway (ctx context.Context , request * transport.Request , out OnewayOutboundChain ) (transport.Ack , error ) {
152
+ return out .Next (ctx , request )
153
+ }
154
+
155
+ // NopOnewayOutbound is an oneway outbound middleware that does not do
156
+ // anything special. It simply calls the underlying OnewayOutbound.
157
+ var NopOnewayOutbound OnewayOutbound = nopOnewayOutbound {}
158
+
159
+ type nopStreamOutbound struct {}
160
+
161
+ func (nopStreamOutbound ) CallStream (ctx context.Context , requestMeta * transport.StreamRequest , out StreamOutboundChain ) (* transport.ClientStream , error ) {
162
+ return out .Next (ctx , requestMeta )
163
+ }
164
+
165
+ // NopStreamOutbound is a stream outbound middleware that does not do
166
+ // anything special. It simply calls the underlying StreamOutbound.
167
+ var NopStreamOutbound StreamOutbound = nopStreamOutbound {}
168
+
169
+ // ApplyUnaryOutbound applies the given UnaryOutbound interceptor to the given DirectUnaryOutbound transport.
170
+ func ApplyUnaryOutbound (uo UnaryOutboundChain , i UnaryOutbound ) transport.UnaryOutbound {
171
+ return unaryOutboundWithInterceptor {uo : uo , i : i }
172
+ }
173
+
174
+ // ApplyOnewayOutbound applies the given OnewayOutbound interceptor to the given DirectOnewayOutbound transport.
175
+ func ApplyOnewayOutbound (oo OnewayOutboundChain , i OnewayOutbound ) transport.OnewayOutbound {
176
+ return onewayOutboundWithInterceptor {oo : oo , i : i }
177
+ }
178
+
179
+ // ApplyStreamOutbound applies the given StreamOutbound interceptor to the given DirectStreamOutbound transport.
180
+ func ApplyStreamOutbound (so StreamOutboundChain , i StreamOutbound ) transport.StreamOutbound {
181
+ return streamOutboundWithInterceptor {so : so , i : i }
182
+ }
183
+
184
+ type unaryOutboundWithInterceptor struct {
185
+ transport.Outbound
186
+ uo UnaryOutboundChain
187
+ i UnaryOutbound
188
+ }
189
+
190
+ func (uoc unaryOutboundWithInterceptor ) Call (ctx context.Context , request * transport.Request ) (* transport.Response , error ) {
191
+ return uoc .i .Call (ctx , request , uoc .uo )
192
+ }
193
+
194
+ type onewayOutboundWithInterceptor struct {
195
+ transport.Outbound
196
+ oo OnewayOutboundChain
197
+ i OnewayOutbound
198
+ }
199
+
200
+ func (ooc onewayOutboundWithInterceptor ) CallOneway (ctx context.Context , request * transport.Request ) (transport.Ack , error ) {
201
+ return ooc .i .CallOneway (ctx , request , ooc .oo )
202
+ }
203
+
204
+ type streamOutboundWithInterceptor struct {
205
+ transport.Outbound
206
+ so StreamOutboundChain
207
+ i StreamOutbound
208
+ }
209
+
210
+ func (soc streamOutboundWithInterceptor ) CallStream (ctx context.Context , requestMeta * transport.StreamRequest ) (* transport.ClientStream , error ) {
211
+ return soc .i .CallStream (ctx , requestMeta , soc .so )
212
+ }
0 commit comments