-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also improve some of the docs in the main library
- Loading branch information
Showing
14 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
packages: ./grapesy | ||
packages: ./grapesy, ./tutorials/quickstart | ||
|
||
package grapesy | ||
tests: True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Copyright (c) 2023-2024, Well-Typed LLP and Anduril Industries Inc. | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Well-Typed LLP, the name of Anduril | ||
Industries Inc., nor the names of other contributors may be | ||
used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
The protobuf file is a modified version of `examples/protos/helloworld.proto` | ||
from the official gRPC repository at https://github.com/grpc/grpc. | ||
|
||
Its license is reproduced below: | ||
|
||
// Copyright 2015 gRPC authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Data.ProtoLens.Setup | ||
|
||
main = defaultMainGeneratingProtos "proto" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Client (main) where | ||
|
||
import Network.GRPC.Client | ||
import Network.GRPC.Client.StreamType.IO | ||
import Network.GRPC.Common | ||
import Network.GRPC.Common.Protobuf | ||
|
||
import Proto.API.Helloworld | ||
|
||
main :: IO () | ||
main = | ||
withConnection def server $ \conn -> do | ||
let req = defMessage & #name .~ "you" | ||
resp <- nonStreaming conn (rpc @(Protobuf Greeter "sayHello")) req | ||
print resp | ||
where | ||
server :: Server | ||
server = ServerInsecure $ Address "127.0.0.1" defaultInsecurePort Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Server (main) where | ||
|
||
import Network.GRPC.Common | ||
import Network.GRPC.Common.Protobuf | ||
import Network.GRPC.Server.Protobuf | ||
import Network.GRPC.Server.Run | ||
import Network.GRPC.Server.StreamType | ||
|
||
import Proto.API.Helloworld | ||
|
||
methods :: Methods IO (ProtobufMethodsOf Greeter) | ||
methods = | ||
Method (mkNonStreaming sayHello) | ||
$ NoMoreMethods | ||
|
||
sayHello :: Proto HelloRequest -> IO (Proto HelloReply) | ||
sayHello req = do | ||
let resp = defMessage & #message .~ "Hello, " <> req ^. #name | ||
return resp | ||
|
||
main :: IO () | ||
main = | ||
runServerWithHandlers def config $ fromMethods methods | ||
where | ||
config :: ServerConfig | ||
config = ServerConfig { | ||
serverInsecure = Just (InsecureConfig Nothing defaultInsecurePort) | ||
, serverSecure = Nothing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1; | ||
} | ||
|
||
// The response message containing the greetings | ||
message HelloReply { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
cabal-version: 3.0 | ||
name: quickstart | ||
version: 0.1.0 | ||
license: BSD-3-Clause | ||
license-file: LICENSE | ||
author: Edsko de Vries | ||
maintainer: [email protected] | ||
build-type: Custom | ||
extra-source-files: proto/helloworld.proto | ||
|
||
custom-setup | ||
setup-depends: | ||
base | ||
, Cabal | ||
, proto-lens-setup | ||
|
||
common lang | ||
build-depends: base >= 4.14 && < 5 | ||
default-language: Haskell2010 | ||
ghc-options: -Wall | ||
|
||
default-extensions: | ||
DataKinds | ||
OverloadedLabels | ||
OverloadedStrings | ||
TypeApplications | ||
TypeFamilies | ||
|
||
library | ||
import: lang | ||
hs-source-dirs: src | ||
build-tool-depends: proto-lens-protoc:proto-lens-protoc | ||
|
||
build-depends: | ||
, grapesy | ||
, proto-lens-runtime | ||
exposed-modules: | ||
Proto.API.Helloworld | ||
other-modules: | ||
Proto.Helloworld | ||
autogen-modules: | ||
Proto.Helloworld | ||
|
||
executable greeter_server | ||
import: lang | ||
main-is: Server.hs | ||
hs-source-dirs: app | ||
ghc-options: -main-is Server | ||
|
||
build-depends: | ||
, grapesy | ||
, quickstart | ||
|
||
executable greeter_client | ||
import: lang | ||
main-is: Client.hs | ||
hs-source-dirs: app | ||
ghc-options: -main-is Client | ||
|
||
build-depends: | ||
, grapesy | ||
, quickstart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Proto.API.Helloworld ( | ||
module Proto.Helloworld | ||
) where | ||
|
||
import Proto.Helloworld | ||
import Network.GRPC.Common.Protobuf | ||
import Network.GRPC.Common | ||
|
||
{------------------------------------------------------------------------------- | ||
Metadata | ||
-------------------------------------------------------------------------------} | ||
|
||
type instance RequestMetadata (Protobuf Greeter meth) = NoMetadata | ||
type instance ResponseInitialMetadata (Protobuf Greeter meth) = NoMetadata | ||
type instance ResponseTrailingMetadata (Protobuf Greeter meth) = NoMetadata |