mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-26 21:19:43 +01:00
MONAPP-1369: Server options for generated code. (#76)
* add ServiceOptions for generated servers * drop opt prefix in ServiceOptions fields * add default options * tweak exports, add docs * re-export stuff from Generated so that users need don't need to import lots of modules * remove threaded from library -- doesn't do anything * add defaultServiceOptions export * more exports * export GRPCMethodType
This commit is contained in:
parent
7d5df1d204
commit
1d8f811906
3 changed files with 70 additions and 4 deletions
|
@ -85,7 +85,7 @@ library
|
||||||
, grpc/impl/codegen/slice.h
|
, grpc/impl/codegen/slice.h
|
||||||
build-tools: c2hs
|
build-tools: c2hs
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-unused-do-bind -threaded
|
ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-unused-do-bind
|
||||||
include-dirs: include
|
include-dirs: include
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-extensions: CPP
|
default-extensions: CPP
|
||||||
|
|
|
@ -6,6 +6,9 @@ module Network.GRPC.HighLevel (
|
||||||
, StatusDetails(..)
|
, StatusDetails(..)
|
||||||
, StatusCode(..)
|
, StatusCode(..)
|
||||||
, GRPCIOError(..)
|
, GRPCIOError(..)
|
||||||
|
, GRPCImpl(..)
|
||||||
|
, MkHandler
|
||||||
|
, ServiceOptions(..)
|
||||||
|
|
||||||
-- * Server
|
-- * Server
|
||||||
, Handler(..)
|
, Handler(..)
|
||||||
|
@ -47,4 +50,5 @@ module Network.GRPC.HighLevel (
|
||||||
where
|
where
|
||||||
|
|
||||||
import Network.GRPC.HighLevel.Server
|
import Network.GRPC.HighLevel.Server
|
||||||
|
import Network.GRPC.HighLevel.Generated
|
||||||
import Network.GRPC.LowLevel
|
import Network.GRPC.LowLevel
|
||||||
|
|
|
@ -2,11 +2,39 @@
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Network.GRPC.HighLevel.Generated where
|
module Network.GRPC.HighLevel.Generated (
|
||||||
|
-- * Types
|
||||||
|
MetadataMap(..)
|
||||||
|
, MethodName(..)
|
||||||
|
, GRPCMethodType(..)
|
||||||
|
, GRPCImpl(..)
|
||||||
|
, MkHandler
|
||||||
|
, Host(..)
|
||||||
|
, Port(..)
|
||||||
|
, StatusDetails(..)
|
||||||
|
, StatusCode(..)
|
||||||
|
, GRPCIOError(..)
|
||||||
|
|
||||||
import Network.GRPC.HighLevel.Server
|
-- * Server
|
||||||
import Network.GRPC.LowLevel.Call
|
, ServiceOptions(..)
|
||||||
|
, defaultServiceOptions
|
||||||
|
, ServerCall(..)
|
||||||
|
, serverCallCancel
|
||||||
|
, serverCallIsExpired
|
||||||
|
, ServerRequest(..)
|
||||||
|
, ServerResponse(..)
|
||||||
|
|
||||||
|
-- * Server Auth
|
||||||
|
, ServerSSLConfig(..)
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
import Network.GRPC.HighLevel.Server
|
||||||
|
import Network.GRPC.LowLevel
|
||||||
|
import Network.GRPC.LowLevel.Call
|
||||||
|
import System.IO (hPutStrLn, stderr)
|
||||||
|
|
||||||
-- | Used at the kind level as a parameter to service definitions
|
-- | Used at the kind level as a parameter to service definitions
|
||||||
-- generated by the grpc compiler, with the effect of having the
|
-- generated by the grpc compiler, with the effect of having the
|
||||||
|
@ -22,3 +50,37 @@ type instance MkHandler 'ServerImpl 'Normal i o = ServerHandler i
|
||||||
type instance MkHandler 'ServerImpl 'ClientStreaming i o = ServerReaderHandler i o
|
type instance MkHandler 'ServerImpl 'ClientStreaming i o = ServerReaderHandler i o
|
||||||
type instance MkHandler 'ServerImpl 'ServerStreaming i o = ServerWriterHandler i o
|
type instance MkHandler 'ServerImpl 'ServerStreaming i o = ServerWriterHandler i o
|
||||||
type instance MkHandler 'ServerImpl 'BiDiStreaming i o = ServerRWHandler i o
|
type instance MkHandler 'ServerImpl 'BiDiStreaming i o = ServerRWHandler i o
|
||||||
|
|
||||||
|
-- | Options for a service that was generated from a .proto file. This is
|
||||||
|
-- essentially 'ServerOptions' with the handler fields removed.
|
||||||
|
data ServiceOptions = ServiceOptions
|
||||||
|
{ serverHost :: Host
|
||||||
|
-- ^ Name of the host the server is running on.
|
||||||
|
, serverPort :: Port
|
||||||
|
-- ^ Port on which to listen for requests.
|
||||||
|
, useCompression :: Bool
|
||||||
|
-- ^ Whether to use compression when communicating with the client.
|
||||||
|
, userAgentPrefix :: String
|
||||||
|
-- ^ Optional custom prefix to add to the user agent string.
|
||||||
|
, userAgentSuffix :: String
|
||||||
|
-- ^ Optional custom suffix to add to the user agent string.
|
||||||
|
, initialMetadata :: MetadataMap
|
||||||
|
-- ^ Metadata to send at the beginning of each call.
|
||||||
|
, sslConfig :: Maybe ServerSSLConfig
|
||||||
|
-- ^ Security configuration.
|
||||||
|
, logger :: String -> IO ()
|
||||||
|
-- ^ Logging function to use to log errors in handling calls.
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultServiceOptions :: ServiceOptions
|
||||||
|
defaultServiceOptions = ServiceOptions
|
||||||
|
-- names are fully qualified because we use the same fields in LowLevel.
|
||||||
|
{ Network.GRPC.HighLevel.Generated.serverHost = "localhost"
|
||||||
|
, Network.GRPC.HighLevel.Generated.serverPort = 50051
|
||||||
|
, Network.GRPC.HighLevel.Generated.useCompression = False
|
||||||
|
, Network.GRPC.HighLevel.Generated.userAgentPrefix = "grpc-haskell/0.0.0"
|
||||||
|
, Network.GRPC.HighLevel.Generated.userAgentSuffix = ""
|
||||||
|
, Network.GRPC.HighLevel.Generated.initialMetadata = mempty
|
||||||
|
, Network.GRPC.HighLevel.Generated.sslConfig = Nothing
|
||||||
|
, Network.GRPC.HighLevel.Generated.logger = hPutStrLn stderr
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue