-
Notifications
You must be signed in to change notification settings - Fork 425
Try gRPC Swift in Google Cloud Shell
Google Cloud Shell is a free and easy-to-use Linux shell that is available with every Google Cloud developer account. You can sign up for a free Google Cloud developer account here.
Visit console.cloud.google.com and click on the small icon in the top bar that contains the console prompt (>_
). The Google Cloud Shell should open at the bottom of your browser window
(for details about Google Cloud Shell see the online documentation.
sudo apt-get update
sudo apt-get install -y clang clang-3.8 lldb-3.8 libicu-dev libtool libcurl4-openssl-dev libbsd-dev build-essential libssl-dev uuid-dev curl unzip
cd
mkdir -p local
vi ~/.bashrc
# and then add the following line:
export PATH=.:$HOME/local/bin:$PATH
source ~/.bashrc
SWIFT_BRANCH=swift-3.1.1-release
SWIFT_VERSION=swift-3.1.1-RELEASE
SWIFT_PLATFORM=ubuntu14.04
SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM.tar.gz
echo $SWIFT_URL
curl -fSsL $SWIFT_URL -o swift.tar.gz
tar -xzf swift.tar.gz --strip-components=2 --directory=local
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip
echo $PROTOC_URL
curl -fSsL $PROTOC_URL -o protoc.zip
unzip protoc.zip -d local
git clone https://github.com/grpc/grpc-swift
cd grpc-swift/Examples/Echo/PackageManager
make
.build/debug/Echo serve &
.build/debug/Echo get
.build/debug/Echo expand
.build/debug/Echo collect
.build/debug/Echo update
The four services that you've called illustrate the four API modes of gRPC: Unary, Server Streaming, Client Streaming, and Bidirectional Streaming. See the echo.proto
file for the service definition and main.swift
and EchoProvider.swift
for client and server implementations, respectively. As a gRPC user, that's all the code that you have to write! Everything else is in support libraries or generated by the Protocol Buffer and gRPC plugins.