mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-15 07:39:43 +01:00
169dbb7fff
* add basic tutorial, re-export client stuff in HighLevel.Generated * add a relative link in README.md * forgot to document the language extensions * cabal file fixup * more context to compile-proto-file * haskell syntax highlighting in markdown * link to gRPC official tutorials for basic concepts * add a note on how to build the examples * prominent notice of required gRPC version * fix typo * do some error handling, show how to run the example executables * use mapM
39 lines
1.4 KiB
Haskell
39 lines
1.4 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
{-# LANGUAGE GADTs #-}
|
|
|
|
import Arithmetic
|
|
import Network.GRPC.HighLevel.Generated
|
|
|
|
clientConfig :: ClientConfig
|
|
clientConfig = ClientConfig { clientServerHost = "localhost"
|
|
, clientServerPort = 50051
|
|
, clientArgs = []
|
|
, clientSSLConfig = Nothing
|
|
}
|
|
|
|
main :: IO ()
|
|
main = withGRPCClient clientConfig $ \client -> do
|
|
(Arithmetic arithmeticAdd arithmeticRunningSum) <- arithmeticClient client
|
|
|
|
-- Request for the Add RPC
|
|
ClientNormalResponse (OneInt x) _meta1 _meta2 _status _details
|
|
<- arithmeticAdd (ClientNormalRequest (TwoInts 2 2) 1 [])
|
|
putStrLn ("2 + 2 = " ++ show x)
|
|
|
|
-- Request for the RunningSum RPC
|
|
ClientWriterResponse reply _streamMeta1 _streamMeta2 streamStatus streamDtls
|
|
<- arithmeticRunningSum $ ClientWriterRequest 1 [] $ \send -> do
|
|
eithers <- mapM send [OneInt 1, OneInt 2, OneInt 3]
|
|
:: IO [Either GRPCIOError ()]
|
|
case sequence eithers of
|
|
Left err -> error ("Error while streaming: " ++ show err)
|
|
Right _ -> return ()
|
|
|
|
case reply of
|
|
Just (OneInt y) -> print ("1 + 2 + 3 = " ++ show y)
|
|
Nothing -> putStrLn ("Client stream failed with status "
|
|
++ show streamStatus
|
|
++ " and details "
|
|
++ show streamDtls)
|
|
return ()
|