mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-30 06:59:43 +01:00
d46c0c1c94
* Remove explicit host:port parameter from clientRequest * Save ClientConfig in Client ADT; derive host:port string as needed * Add Port newtype and endpoint string constructor fn * Introduce Endpoint newtype for host:port strings; derive them as needed; misc cleanup * Clean up echo client
24 lines
711 B
Haskell
24 lines
711 B
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
|
|
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
|
|
|
|
import Control.Monad
|
|
import Network.GRPC.LowLevel
|
|
|
|
echoMethod = MethodName "/echo.Echo/DoEcho"
|
|
|
|
unregistered c = do
|
|
clientRequest c echoMethod 1 "hi" mempty
|
|
|
|
registered c = do
|
|
meth <- clientRegisterMethod c echoMethod Normal
|
|
clientRegisteredRequest c meth 1 "hi" mempty
|
|
|
|
run f = withGRPC $ \g -> withClient g (ClientConfig "localhost" 50051) $ \c ->
|
|
f c >>= \case
|
|
Left e -> error $ "Got client error: " ++ show e
|
|
_ -> return ()
|
|
|
|
main = replicateM_ 100 $ run $
|
|
registered
|