mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-05 18:59:42 +01:00
9a3be32ed7
* echo client/server example: dead code removal, add command line params, improve output messages * Add nix-build result to .gitignore * Merge echo-client and echo-server directories to echo-hs/ directory; rename main modules accordingly * Use our protobuf compiler to generate bindings for the Echo service * Simplify echo.proto to just one endpoint; use highlevel client/server interfaces and codegen for echo example * Remove repetition counts and thread spawns from echo client, parameterize payload * Update default.nix
42 lines
1.8 KiB
Haskell
42 lines
1.8 KiB
Haskell
{-# LANGUAGE DataKinds #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE GADTs #-}
|
|
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
{-# LANGUAGE TypeOperators #-}
|
|
|
|
import Data.ByteString (ByteString)
|
|
import Data.Maybe (fromMaybe)
|
|
import GHC.Generics (Generic)
|
|
import Network.GRPC.HighLevel.Generated (GRPCMethodType (..),
|
|
Host (..), Port (..),
|
|
ServerRequest (..),
|
|
ServerResponse (..),
|
|
StatusCode (..),
|
|
defaultServiceOptions,
|
|
serverHost, serverPort)
|
|
import Options.Generic
|
|
|
|
import Echo
|
|
|
|
data Args = Args
|
|
{ bind :: Maybe ByteString <?> "grpc endpoint hostname (default \"localhost\")"
|
|
, port :: Maybe Int <?> "grpc endpoint port (default 50051)"
|
|
} deriving (Generic, Show)
|
|
instance ParseRecord Args
|
|
|
|
doEcho :: ServerRequest 'Normal EchoRequest EchoResponse
|
|
-> IO (ServerResponse 'Normal EchoResponse)
|
|
doEcho (ServerNormalRequest _meta (EchoRequest pay)) = do
|
|
return (ServerNormalResponse (EchoResponse pay) mempty StatusOk "")
|
|
|
|
main :: IO ()
|
|
main = do
|
|
Args{..} <- getRecord "Runs the echo service"
|
|
let opts = defaultServiceOptions
|
|
{ serverHost = Host . fromMaybe "localhost" . unHelpful $ bind
|
|
, serverPort = Port . fromMaybe 50051 . unHelpful $ port
|
|
}
|
|
echoServer Echo{ echoDoEcho = doEcho } opts
|