Skip to content

Commit 255d585

Browse files
committed
Nicer overloads for adding interceptors to server
1 parent 5dcf129 commit 255d585

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Sources/GRPCCore/GRPCServer.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ public final class GRPCServer: Sendable {
138138
}
139139
}
140140

141+
/// Creates a new server with no resources.
142+
///
143+
/// - Parameters:
144+
/// - transport: The transport the server should listen on.
145+
/// - services: Services offered by the server.
146+
/// - interceptors: A collection of interceptors providing cross-cutting functionality to each
147+
/// accepted RPC. The order in which interceptors are added reflects the order in which they
148+
/// are called. The first interceptor added will be the first interceptor to intercept each
149+
/// request. The last interceptor added will be the final interceptor to intercept each
150+
/// request before calling the appropriate handler.
151+
public convenience init(
152+
transport: any ServerTransport,
153+
services: [any RegistrableRPCService],
154+
interceptors: [any ServerInterceptor] = []
155+
) {
156+
self.init(
157+
transport: transport,
158+
services: services,
159+
interceptors: interceptors.map { .allServices(interceptor: $0) }
160+
)
161+
}
162+
141163
/// Creates a new server with no resources.
142164
///
143165
/// - Parameters:
@@ -161,6 +183,28 @@ public final class GRPCServer: Sendable {
161183
self.init(transport: transport, router: router, interceptors: interceptors)
162184
}
163185

186+
/// Creates a new server with no resources.
187+
///
188+
/// - Parameters:
189+
/// - transport: The transport the server should listen on.
190+
/// - router: A ``RPCRouter`` used by the server to route accepted streams to method handlers.
191+
/// - interceptors: A collection of interceptors providing cross-cutting functionality to each
192+
/// accepted RPC. The order in which interceptors are added reflects the order in which they
193+
/// are called. The first interceptor added will be the first interceptor to intercept each
194+
/// request. The last interceptor added will be the final interceptor to intercept each
195+
/// request before calling the appropriate handler.
196+
public convenience init(
197+
transport: any ServerTransport,
198+
router: RPCRouter,
199+
interceptors: [any ServerInterceptor] = []
200+
) {
201+
self.init(
202+
transport: transport,
203+
router: router,
204+
interceptors: interceptors.map { .allServices(interceptor: $0)}
205+
)
206+
}
207+
164208
/// Creates a new server with no resources.
165209
///
166210
/// - Parameters:

0 commit comments

Comments
 (0)