ソースを参照

New Spanner sample and top-level README for Google examples.

Tim Burks 8 年 前
コミット
63cfec0858

+ 3 - 10
Examples/Google/Datastore/README.md

@@ -11,14 +11,7 @@ Buffer and gRPC plugins, so please be sure these are in your
 path. The plugins can be built by running `make` in the 
 path. The plugins can be built by running `make` in the 
 top-level Plugins directory.
 top-level Plugins directory.
 
 
-Calls require a Google project ID and service account credentials.
+## Prerequisites
 
 
-To create a project ID, visit the 
-[Google Cloud Console](https://cloud.google.com/console).
-
-Service account support is provided by Google's 
-[Auth Library for Swift](https://github.com/google/auth-library-swift).
-After enabling the Cloud Natural Language API for your project,
-create and download service account credentials. Then set the
-GOOGLE_APPLICATION_CREDENTIALS environment variable to point to 
-the file containing these credentials.
+Please be sure to perform the preliminary steps in 
+[Examples/Google/README](../README.md).

+ 3 - 11
Examples/Google/NaturalLanguage/README.md

@@ -11,15 +11,7 @@ Buffer and gRPC plugins, so please be sure these are in your
 path. The plugins can be built by running `make` in the 
 path. The plugins can be built by running `make` in the 
 top-level Plugins directory.
 top-level Plugins directory.
 
 
-Calls require a Google project ID and service account credentials.
-
-To create a project ID, visit the 
-[Google Cloud Console](https://cloud.google.com/console).
-
-Service account support is provided by Google's 
-[Auth Library for Swift](https://github.com/google/auth-library-swift).
-After enabling the Cloud Natural Language API for your project,
-create and download service account credentials. Then set the
-GOOGLE_APPLICATION_CREDENTIALS environment variable to point to 
-the file containing these credentials.
+## Prerequisites
 
 
+Please be sure to perform the preliminary steps in
+[Examples/Google/README](../README.md).

+ 40 - 0
Examples/Google/README.md

@@ -0,0 +1,40 @@
+# Calling the Google gRPC APIs
+
+This directory contains samples that call selected
+Google gRPC APIs. Samples are typically quite basic
+and demonstrate how to directly call gRPC APIs from 
+generated client support code. In practice, this code
+would be wrapped with higher-level Swift code.
+
+Each sample uses protoc and the Swift Protocol
+Buffer and gRPC plugins, so please be sure these are in your
+path. The plugins can be built by running `make` in the 
+top-level Plugins directory.
+
+Calls to Google APIs require a Google project ID, 
+API activation, and service account credentials.
+
+1. To create a project ID, visit the 
+[Google Cloud Console](https://cloud.google.com/console).
+Your selected project ID should be shown in the top bar just
+to the right of the **Google Cloud Platform** label. Click
+on this to change projects or create a new one.
+
+2. To activate an API, visit the Google Cloud Console,
+go to the **APIs & Services** section and use its **Library**
+subsection to lookup the API and click on the **Enable**
+button. If you instead see a button labeled **Manage**,
+the API is already activated.
+
+3. To create service account credentials, again visit
+the Google Cloud Console, go to the **APIs & Services**
+section and use the **Credentials** subsection. When you
+create these credentials, you'll be prompted to download
+them. Do that, and then set the `GOOGLE_APPLICATION_CREDENTIALS` 
+environment variable to point to the file containing 
+your credentials.
+
+Service account support is provided by Google's 
+[Auth Library for Swift](https://github.com/google/auth-library-swift).
+To learn more about service accounts, please see 
+[Understanding Service Accounts](https://cloud.google.com/iam/docs/understanding-service-accounts).

+ 9 - 0
Examples/Google/Spanner/Makefile

@@ -0,0 +1,9 @@
+
+all:
+	swift build -c release
+	cp .build/release/Spanner .
+
+clean :
+	rm -rf Packages googleapis .build
+	rm -f Package.pins Spanner Sources/*.pb.swift Sources/swiftgrpc.log google.json
+	rm -rf Package.resolved

+ 25 - 0
Examples/Google/Spanner/Package.swift

@@ -0,0 +1,25 @@
+/*
+ * Copyright 2017, gRPC Authors All rights reserved.
+ *
+ * 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.
+ */
+import PackageDescription
+let package = Package (
+    name: "Spanner",
+    dependencies: [
+        .Package(url: "https://github.com/grpc/grpc-swift.git", Version(0,3,0)),
+        .Package(url: "https://github.com/apple/swift-protobuf.git", Version(1,0,2)),
+        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,4)),
+	.Package(url: "https://github.com/kylef/Commander.git", Version(0,8,0)),
+    ]
+)

+ 11 - 0
Examples/Google/Spanner/README.md

@@ -0,0 +1,11 @@
+# Calling the Google Spanner API
+
+This directory contains a very simple sample that calls the 
+[Google Spanner API](https://cloud.google.com/spanner/docs).
+
+Currently it only verifies that the generated code will compile and link.
+
+## Prerequisites
+
+Please be sure to perform the preliminary steps in
+[Examples/Google/README](../README.md).

+ 37 - 0
Examples/Google/Spanner/RUNME

@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Use this script to regenerate the Protocol Buffer and gRPC files
+# needed to build the example.
+#
+# Note that it requires updated protoc, protoc-gen-swift, and
+# protoc-gen-swiftgrpc binaries and assumes that protoc-gen-swift 
+# is installed in $HOME/local/bin.
+
+if [ ! -d "googleapis" ]; then
+  git clone http://github.com/googleapis/googleapis
+fi
+
+protoc \
+	google/spanner/v1/keys.proto \
+	google/spanner/v1/mutation.proto \
+	google/spanner/v1/query_plan.proto \
+	google/spanner/v1/result_set.proto \
+	google/spanner/v1/spanner.proto \
+	google/spanner/v1/transaction.proto \
+	google/spanner/v1/type.proto \
+	google/spanner/admin/instance/v1/spanner_instance_admin.proto \
+	google/spanner/admin/database/v1/spanner_database_admin.proto \
+	google/longrunning/operations.proto \
+	google/rpc/status.proto \
+	google/iam/v1/iam_policy.proto \
+	google/iam/v1/policy.proto \
+ 	-Igoogleapis \
+	--swift_out=googleapis \
+	--swiftgrpc_out=googleapis
+
+# move Swift files to the Sources directory
+find googleapis -name "*.swift" -exec mv {} Sources \;
+
+# remove the grpc service file; we don't need it
+rm Sources/*.server.pb.swift
+

+ 28 - 0
Examples/Google/Spanner/Sources/main.swift

@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017, gRPC Authors All rights reserved.
+ *
+ * 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.
+ */
+import Foundation
+import gRPC
+import OAuth2
+import Commander
+
+Group {
+
+  $0.command("hello") {
+    print("hello")
+  }
+  
+}.run()
+