mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-23 03:29:42 +01:00
Fix examples
Fixes https://github.com/awakesecurity/gRPC-haskell/issues/112
This commit is contained in:
parent
0cb7999e9e
commit
f8b779e2b3
5 changed files with 56 additions and 41 deletions
82
examples/echo/echo-hs/Echo.hs
generated
82
examples/echo/echo-hs/Echo.hs
generated
|
@ -1,49 +1,58 @@
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE GADTs #-}
|
{-# LANGUAGE GADTs #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
|
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
|
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
|
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
|
||||||
|
|
||||||
-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT!
|
-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT!
|
||||||
|
|
||||||
module Echo where
|
module Echo where
|
||||||
import qualified Prelude as Hs
|
import qualified Prelude as Hs
|
||||||
import qualified Proto3.Suite.DotProto as HsProtobuf
|
|
||||||
import qualified Proto3.Suite.Types as HsProtobuf
|
|
||||||
import qualified Proto3.Suite.Class as HsProtobuf
|
import qualified Proto3.Suite.Class as HsProtobuf
|
||||||
|
import qualified Proto3.Suite.DotProto as HsProtobuf
|
||||||
import qualified Proto3.Suite.JSONPB as HsJSONPB
|
import qualified Proto3.Suite.JSONPB as HsJSONPB
|
||||||
import Proto3.Suite.JSONPB ((.=), (.:))
|
import Proto3.Suite.JSONPB ((.=), (.:))
|
||||||
|
import qualified Proto3.Suite.Types as HsProtobuf
|
||||||
import qualified Proto3.Wire as HsProtobuf
|
import qualified Proto3.Wire as HsProtobuf
|
||||||
import Control.Applicative ((<*>), (<|>), (<$>))
|
|
||||||
import qualified Control.Applicative as Hs
|
import qualified Control.Applicative as Hs
|
||||||
|
import Control.Applicative ((<*>), (<|>), (<$>))
|
||||||
|
import qualified Control.DeepSeq as Hs
|
||||||
import qualified Control.Monad as Hs
|
import qualified Control.Monad as Hs
|
||||||
import qualified Data.Text.Lazy as Hs (Text)
|
|
||||||
import qualified Data.ByteString as Hs
|
import qualified Data.ByteString as Hs
|
||||||
import qualified Data.String as Hs (fromString)
|
import qualified Data.Coerce as Hs
|
||||||
import qualified Data.Vector as Hs (Vector)
|
|
||||||
import qualified Data.Int as Hs (Int16, Int32, Int64)
|
import qualified Data.Int as Hs (Int16, Int32, Int64)
|
||||||
import qualified Data.Word as Hs (Word16, Word32, Word64)
|
import qualified Data.List.NonEmpty as Hs (NonEmpty(..))
|
||||||
|
import qualified Data.Map as Hs (Map, mapKeysMonotonic)
|
||||||
import qualified Data.Proxy as Proxy
|
import qualified Data.Proxy as Proxy
|
||||||
import qualified GHC.Generics as Hs
|
import qualified Data.String as Hs (fromString)
|
||||||
|
import qualified Data.Text.Lazy as Hs (Text)
|
||||||
|
import qualified Data.Vector as Hs (Vector)
|
||||||
|
import qualified Data.Word as Hs (Word16, Word32, Word64)
|
||||||
import qualified GHC.Enum as Hs
|
import qualified GHC.Enum as Hs
|
||||||
|
import qualified GHC.Generics as Hs
|
||||||
|
import qualified Unsafe.Coerce as Hs
|
||||||
import Network.GRPC.HighLevel.Generated as HsGRPC
|
import Network.GRPC.HighLevel.Generated as HsGRPC
|
||||||
import Network.GRPC.HighLevel.Client as HsGRPC
|
import Network.GRPC.HighLevel.Client as HsGRPC
|
||||||
import Network.GRPC.HighLevel.Server as HsGRPC hiding (serverLoop)
|
import Network.GRPC.HighLevel.Server as HsGRPC hiding (serverLoop)
|
||||||
import Network.GRPC.HighLevel.Server.Unregistered as HsGRPC
|
import Network.GRPC.HighLevel.Server.Unregistered as HsGRPC
|
||||||
(serverLoop)
|
(serverLoop)
|
||||||
|
|
||||||
data Echo request response = Echo{echoDoEcho ::
|
data Echo request response = Echo{echoDoEcho ::
|
||||||
request 'HsGRPC.Normal Echo.EchoRequest Echo.EchoResponse ->
|
request 'HsGRPC.Normal Echo.EchoRequest Echo.EchoResponse ->
|
||||||
Hs.IO (response 'HsGRPC.Normal Echo.EchoResponse)}
|
Hs.IO (response 'HsGRPC.Normal Echo.EchoResponse)}
|
||||||
deriving Hs.Generic
|
deriving Hs.Generic
|
||||||
|
|
||||||
echoServer ::
|
echoServer ::
|
||||||
Echo HsGRPC.ServerRequest HsGRPC.ServerResponse ->
|
Echo HsGRPC.ServerRequest HsGRPC.ServerResponse ->
|
||||||
HsGRPC.ServiceOptions -> Hs.IO ()
|
HsGRPC.ServiceOptions -> Hs.IO ()
|
||||||
echoServer Echo{echoDoEcho = echoDoEcho}
|
echoServer Echo{echoDoEcho = echoDoEcho}
|
||||||
(ServiceOptions serverHost serverPort useCompression
|
(ServiceOptions serverHost serverPort useCompression
|
||||||
userAgentPrefix userAgentSuffix initialMetadata sslConfig logger)
|
userAgentPrefix userAgentSuffix initialMetadata sslConfig logger
|
||||||
|
serverMaxReceiveMessageLength)
|
||||||
= (HsGRPC.serverLoop
|
= (HsGRPC.serverLoop
|
||||||
HsGRPC.defaultOptions{HsGRPC.optNormalHandlers =
|
HsGRPC.defaultOptions{HsGRPC.optNormalHandlers =
|
||||||
[(HsGRPC.UnaryHandler (HsGRPC.MethodName "/echo.Echo/DoEcho")
|
[(HsGRPC.UnaryHandler (HsGRPC.MethodName "/echo.Echo/DoEcho")
|
||||||
|
@ -55,8 +64,9 @@ echoServer Echo{echoDoEcho = echoDoEcho}
|
||||||
optUserAgentPrefix = userAgentPrefix,
|
optUserAgentPrefix = userAgentPrefix,
|
||||||
optUserAgentSuffix = userAgentSuffix,
|
optUserAgentSuffix = userAgentSuffix,
|
||||||
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
|
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
|
||||||
optLogger = logger})
|
optLogger = logger,
|
||||||
|
optMaxReceiveMessageLength = serverMaxReceiveMessageLength})
|
||||||
|
|
||||||
echoClient ::
|
echoClient ::
|
||||||
HsGRPC.Client ->
|
HsGRPC.Client ->
|
||||||
Hs.IO (Echo HsGRPC.ClientRequest HsGRPC.ClientResult)
|
Hs.IO (Echo HsGRPC.ClientRequest HsGRPC.ClientResult)
|
||||||
|
@ -65,13 +75,15 @@ echoClient client
|
||||||
((Hs.pure (HsGRPC.clientRequest client)) <*>
|
((Hs.pure (HsGRPC.clientRequest client)) <*>
|
||||||
(HsGRPC.clientRegisterMethod client
|
(HsGRPC.clientRegisterMethod client
|
||||||
(HsGRPC.MethodName "/echo.Echo/DoEcho")))
|
(HsGRPC.MethodName "/echo.Echo/DoEcho")))
|
||||||
|
|
||||||
data EchoRequest = EchoRequest{echoRequestMessage :: Hs.Text}
|
newtype EchoRequest = EchoRequest{echoRequestMessage :: Hs.Text}
|
||||||
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic)
|
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData)
|
||||||
|
|
||||||
instance HsProtobuf.Named EchoRequest where
|
instance HsProtobuf.Named EchoRequest where
|
||||||
nameOf _ = (Hs.fromString "EchoRequest")
|
nameOf _ = (Hs.fromString "EchoRequest")
|
||||||
|
|
||||||
|
instance HsProtobuf.HasDefault EchoRequest
|
||||||
|
|
||||||
instance HsProtobuf.Message EchoRequest where
|
instance HsProtobuf.Message EchoRequest where
|
||||||
encodeMessage _
|
encodeMessage _
|
||||||
EchoRequest{echoRequestMessage = echoRequestMessage}
|
EchoRequest{echoRequestMessage = echoRequestMessage}
|
||||||
|
@ -88,23 +100,23 @@ instance HsProtobuf.Message EchoRequest where
|
||||||
(HsProtobuf.Single "message")
|
(HsProtobuf.Single "message")
|
||||||
[]
|
[]
|
||||||
"")]
|
"")]
|
||||||
|
|
||||||
instance HsJSONPB.ToJSONPB EchoRequest where
|
instance HsJSONPB.ToJSONPB EchoRequest where
|
||||||
toJSONPB (EchoRequest f1) = (HsJSONPB.object ["message" .= f1])
|
toJSONPB (EchoRequest f1) = (HsJSONPB.object ["message" .= f1])
|
||||||
toEncodingPB (EchoRequest f1) = (HsJSONPB.pairs ["message" .= f1])
|
toEncodingPB (EchoRequest f1) = (HsJSONPB.pairs ["message" .= f1])
|
||||||
|
|
||||||
instance HsJSONPB.FromJSONPB EchoRequest where
|
instance HsJSONPB.FromJSONPB EchoRequest where
|
||||||
parseJSONPB
|
parseJSONPB
|
||||||
= (HsJSONPB.withObject "EchoRequest"
|
= (HsJSONPB.withObject "EchoRequest"
|
||||||
(\ obj -> (Hs.pure EchoRequest) <*> obj .: "message"))
|
(\ obj -> (Hs.pure EchoRequest) <*> obj .: "message"))
|
||||||
|
|
||||||
instance HsJSONPB.ToJSON EchoRequest where
|
instance HsJSONPB.ToJSON EchoRequest where
|
||||||
toJSON = HsJSONPB.toAesonValue
|
toJSON = HsJSONPB.toAesonValue
|
||||||
toEncoding = HsJSONPB.toAesonEncoding
|
toEncoding = HsJSONPB.toAesonEncoding
|
||||||
|
|
||||||
instance HsJSONPB.FromJSON EchoRequest where
|
instance HsJSONPB.FromJSON EchoRequest where
|
||||||
parseJSON = HsJSONPB.parseJSONPB
|
parseJSON = HsJSONPB.parseJSONPB
|
||||||
|
|
||||||
instance HsJSONPB.ToSchema EchoRequest where
|
instance HsJSONPB.ToSchema EchoRequest where
|
||||||
declareNamedSchema _
|
declareNamedSchema _
|
||||||
= do let declare_message = HsJSONPB.declareSchemaRef
|
= do let declare_message = HsJSONPB.declareSchemaRef
|
||||||
|
@ -120,13 +132,15 @@ instance HsJSONPB.ToSchema EchoRequest where
|
||||||
HsJSONPB._schemaProperties =
|
HsJSONPB._schemaProperties =
|
||||||
HsJSONPB.insOrdFromList
|
HsJSONPB.insOrdFromList
|
||||||
[("message", echoRequestMessage)]}})
|
[("message", echoRequestMessage)]}})
|
||||||
|
|
||||||
data EchoResponse = EchoResponse{echoResponseMessage :: Hs.Text}
|
newtype EchoResponse = EchoResponse{echoResponseMessage :: Hs.Text}
|
||||||
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic)
|
deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData)
|
||||||
|
|
||||||
instance HsProtobuf.Named EchoResponse where
|
instance HsProtobuf.Named EchoResponse where
|
||||||
nameOf _ = (Hs.fromString "EchoResponse")
|
nameOf _ = (Hs.fromString "EchoResponse")
|
||||||
|
|
||||||
|
instance HsProtobuf.HasDefault EchoResponse
|
||||||
|
|
||||||
instance HsProtobuf.Message EchoResponse where
|
instance HsProtobuf.Message EchoResponse where
|
||||||
encodeMessage _
|
encodeMessage _
|
||||||
EchoResponse{echoResponseMessage = echoResponseMessage}
|
EchoResponse{echoResponseMessage = echoResponseMessage}
|
||||||
|
@ -143,23 +157,23 @@ instance HsProtobuf.Message EchoResponse where
|
||||||
(HsProtobuf.Single "message")
|
(HsProtobuf.Single "message")
|
||||||
[]
|
[]
|
||||||
"")]
|
"")]
|
||||||
|
|
||||||
instance HsJSONPB.ToJSONPB EchoResponse where
|
instance HsJSONPB.ToJSONPB EchoResponse where
|
||||||
toJSONPB (EchoResponse f1) = (HsJSONPB.object ["message" .= f1])
|
toJSONPB (EchoResponse f1) = (HsJSONPB.object ["message" .= f1])
|
||||||
toEncodingPB (EchoResponse f1) = (HsJSONPB.pairs ["message" .= f1])
|
toEncodingPB (EchoResponse f1) = (HsJSONPB.pairs ["message" .= f1])
|
||||||
|
|
||||||
instance HsJSONPB.FromJSONPB EchoResponse where
|
instance HsJSONPB.FromJSONPB EchoResponse where
|
||||||
parseJSONPB
|
parseJSONPB
|
||||||
= (HsJSONPB.withObject "EchoResponse"
|
= (HsJSONPB.withObject "EchoResponse"
|
||||||
(\ obj -> (Hs.pure EchoResponse) <*> obj .: "message"))
|
(\ obj -> (Hs.pure EchoResponse) <*> obj .: "message"))
|
||||||
|
|
||||||
instance HsJSONPB.ToJSON EchoResponse where
|
instance HsJSONPB.ToJSON EchoResponse where
|
||||||
toJSON = HsJSONPB.toAesonValue
|
toJSON = HsJSONPB.toAesonValue
|
||||||
toEncoding = HsJSONPB.toAesonEncoding
|
toEncoding = HsJSONPB.toAesonEncoding
|
||||||
|
|
||||||
instance HsJSONPB.FromJSON EchoResponse where
|
instance HsJSONPB.FromJSON EchoResponse where
|
||||||
parseJSON = HsJSONPB.parseJSONPB
|
parseJSON = HsJSONPB.parseJSONPB
|
||||||
|
|
||||||
instance HsJSONPB.ToSchema EchoResponse where
|
instance HsJSONPB.ToSchema EchoResponse where
|
||||||
declareNamedSchema _
|
declareNamedSchema _
|
||||||
= do let declare_message = HsJSONPB.declareSchemaRef
|
= do let declare_message = HsJSONPB.declareSchemaRef
|
||||||
|
@ -174,4 +188,4 @@ instance HsJSONPB.ToSchema EchoResponse where
|
||||||
Hs.Just HsJSONPB.SwaggerObject},
|
Hs.Just HsJSONPB.SwaggerObject},
|
||||||
HsJSONPB._schemaProperties =
|
HsJSONPB._schemaProperties =
|
||||||
HsJSONPB.insOrdFromList
|
HsJSONPB.insOrdFromList
|
||||||
[("message", echoResponseMessage)]}})
|
[("message", echoResponseMessage)]}})
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Function (fix)
|
import Data.Function (fix)
|
||||||
import Data.Monoid
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Word
|
import Data.Word
|
||||||
import GHC.Generics (Generic)
|
import GHC.Generics (Generic)
|
||||||
|
|
6
examples/tutorial/Arithmetic.hs
generated
6
examples/tutorial/Arithmetic.hs
generated
|
@ -62,7 +62,8 @@ arithmeticServer
|
||||||
Arithmetic{arithmeticAdd = arithmeticAdd,
|
Arithmetic{arithmeticAdd = arithmeticAdd,
|
||||||
arithmeticRunningSum = arithmeticRunningSum}
|
arithmeticRunningSum = arithmeticRunningSum}
|
||||||
(ServiceOptions serverHost serverPort useCompression
|
(ServiceOptions serverHost serverPort useCompression
|
||||||
userAgentPrefix userAgentSuffix initialMetadata sslConfig logger)
|
userAgentPrefix userAgentSuffix initialMetadata sslConfig logger
|
||||||
|
serverMaxReceiveMessageLength)
|
||||||
= (HsGRPC.serverLoop
|
= (HsGRPC.serverLoop
|
||||||
HsGRPC.defaultOptions{HsGRPC.optNormalHandlers =
|
HsGRPC.defaultOptions{HsGRPC.optNormalHandlers =
|
||||||
[(HsGRPC.UnaryHandler
|
[(HsGRPC.UnaryHandler
|
||||||
|
@ -79,7 +80,8 @@ arithmeticServer
|
||||||
optUserAgentPrefix = userAgentPrefix,
|
optUserAgentPrefix = userAgentPrefix,
|
||||||
optUserAgentSuffix = userAgentSuffix,
|
optUserAgentSuffix = userAgentSuffix,
|
||||||
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
|
optInitialMetadata = initialMetadata, optSSLConfig = sslConfig,
|
||||||
optLogger = logger})
|
optLogger = logger,
|
||||||
|
optMaxReceiveMessageLength = serverMaxReceiveMessageLength})
|
||||||
|
|
||||||
arithmeticClient ::
|
arithmeticClient ::
|
||||||
HsGRPC.Client ->
|
HsGRPC.Client ->
|
||||||
|
|
|
@ -97,6 +97,7 @@ executable echo-server
|
||||||
, async
|
, async
|
||||||
, bytestring == 0.10.*
|
, bytestring == 0.10.*
|
||||||
, containers >=0.5 && <0.7
|
, containers >=0.5 && <0.7
|
||||||
|
, deepseq
|
||||||
, grpc-haskell
|
, grpc-haskell
|
||||||
, grpc-haskell-core
|
, grpc-haskell-core
|
||||||
, optparse-generic
|
, optparse-generic
|
||||||
|
@ -169,6 +170,7 @@ executable echo-client
|
||||||
, async
|
, async
|
||||||
, bytestring == 0.10.*
|
, bytestring == 0.10.*
|
||||||
, containers >=0.5 && <0.7
|
, containers >=0.5 && <0.7
|
||||||
|
, deepseq
|
||||||
, grpc-haskell
|
, grpc-haskell
|
||||||
, grpc-haskell-core
|
, grpc-haskell-core
|
||||||
, optparse-generic
|
, optparse-generic
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
# If you would like to test and build changes quickly using `cabal`, run:
|
# If you would like to test and build changes quickly using `cabal`, run:
|
||||||
#
|
#
|
||||||
# $ # Consider adding the following command to your `~/.profile`
|
# $ nix-shell
|
||||||
# $ NIX_PATH="${NIX_PATH}:ssh-config-file=${HOME}/.ssh/config:ssh-auth-sock=${SSH_AUTH_SOCK}"
|
# [nix-shell]$ cabal configure --enable-tests && cabal test
|
||||||
# $ nix-shell -A grpc-haskell.env release.nix
|
|
||||||
# [nix-shell]$ cabal configure --enable-tests && cabal build && cabal test
|
|
||||||
#
|
#
|
||||||
# This will open up a Nix shell where all of your Haskell tools will work like
|
# This will open up a Nix shell where all of your Haskell tools will work like
|
||||||
# normal, except that all dependencies (including C libraries) are managed by
|
# normal, except that all dependencies (including C libraries) are managed by
|
||||||
|
|
Loading…
Reference in a new issue