Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit d3459db

Browse files
authored
Multiplex gRPC servers (#309)
1 parent 1adc532 commit d3459db

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

grpc/server/src/Mu/GRpc/Server.hs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Mu.GRpc.Server
2929
, runGRpcAppTLS, TLSSettings
3030
-- * Convert a 'Server' into a WAI application
3131
, gRpcApp, gRpcAppTrans
32+
, WrappedServer(..), gRpcMultipleApp, gRpcMultipleAppTrans
3233
-- * Raise errors as exceptions in IO
3334
, raiseErrors, liftServerConduit
3435
-- * Re-export useful instances
@@ -147,6 +148,31 @@ gRpcAppTrans protocol f svr
147148
= Wai.grpcApp [uncompressed, gzip]
148149
(gRpcServerHandlers protocol f svr)
149150

151+
-- | Turn several Mu 'Server's into a WAI 'Application'.
152+
--
153+
-- These 'Application's can be later combined using,
154+
-- for example, @wai-routes@, or you can add middleware
155+
-- from @wai-extra@, among others.
156+
gRpcMultipleApp
157+
:: Proxy protocol
158+
-> [WrappedServer protocol ServerErrorIO]
159+
-> Application
160+
gRpcMultipleApp protocol = gRpcMultipleAppTrans protocol id
161+
162+
-- | Turn several Mu 'Server's into a WAI 'Application'.
163+
--
164+
-- These 'Application's can be later combined using,
165+
-- for example, @wai-routes@, or you can add middleware
166+
-- from @wai-extra@, among others.
167+
gRpcMultipleAppTrans
168+
:: Proxy protocol
169+
-> (forall a. m a -> ServerErrorIO a)
170+
-> [WrappedServer protocol m]
171+
-> Application
172+
gRpcMultipleAppTrans protocol f svr
173+
= Wai.grpcApp [uncompressed, gzip]
174+
(concatMap (gRpcServerHandlersS protocol f) svr)
175+
150176
gRpcServerHandlers
151177
:: forall name services handlers m protocol chn.
152178
( KnownName name
@@ -160,6 +186,21 @@ gRpcServerHandlers pr f (Services svr)
160186
= gRpcServiceHandlers f (Proxy @('Package ('Just name) services)) pr packageName svr
161187
where packageName = BS.pack (nameVal (Proxy @name))
162188

189+
data WrappedServer protocol m where
190+
Srv :: ( KnownName name
191+
, GRpcServiceHandlers ('Package ('Just name) services)
192+
protocol m chn services handlers )
193+
=> ServerT chn () ('Package ('Just name) services) m handlers
194+
-> WrappedServer protocol m
195+
196+
gRpcServerHandlersS
197+
:: Proxy protocol
198+
-> (forall a. m a -> ServerErrorIO a)
199+
-> WrappedServer protocol m
200+
-> [ServiceHandler]
201+
gRpcServerHandlersS pr f (Srv svr)
202+
= gRpcServerHandlers pr f svr
203+
163204
class GRpcServiceHandlers (fullP :: Package snm mnm anm (TypeRef snm))
164205
(p :: GRpcMessageProtocol) (m :: Type -> Type)
165206
(chn :: ServiceChain snm)

0 commit comments

Comments
 (0)