Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/build-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ steps:
waitFor: ['gcf-builder-ready']
id: 'site-tutorial_cloud_bigtable'
args: ['build',
'--env', 'GOOGLE_FUNCTION_SIGNATURE_TYPE=http',
'--env', 'GOOGLE_FUNCTION_TARGET=tutorial_cloud_bigtable',
'--path', 'examples/site/tutorial_cloud_bigtable',
'site-tutorial_cloud_bigtable',
Expand All @@ -370,7 +369,6 @@ steps:
waitFor: ['gcf-builder-ready']
id: 'site-tutorial_cloud_spanner'
args: ['build',
'--env', 'GOOGLE_FUNCTION_SIGNATURE_TYPE=http',
'--env', 'GOOGLE_FUNCTION_TARGET=tutorial_cloud_spanner',
'--path', 'examples/site/tutorial_cloud_spanner',
'site-tutorial_cloud_spanner',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

// [START bigtable_functions_quickstart]
#include <google/cloud/bigtable/table.h>
#include <google/cloud/functions/http_request.h>
#include <google/cloud/functions/http_response.h>
#include <google/cloud/functions/function.h>
#include <algorithm>
#include <cctype>
#include <mutex>
Expand All @@ -25,6 +24,8 @@
namespace gcf = ::google::cloud::functions;
namespace cbt = ::google::cloud::bigtable;

namespace {

cbt::Table get_table_client(std::string project_id, std::string instance_id,
std::string const& table_id) {
static std::mutex mu;
Expand All @@ -42,7 +43,7 @@ cbt::Table get_table_client(std::string project_id, std::string instance_id,
return *table;
}

gcf::HttpResponse tutorial_cloud_bigtable(gcf::HttpRequest request) { // NOLINT
gcf::HttpResponse handle_request(gcf::HttpRequest const& request) {
auto get_header = [h = request.headers()](std::string key) {
std::transform(key.begin(), key.end(), key.begin(),
[](auto x) { return static_cast<char>(std::tolower(x)); });
Expand Down Expand Up @@ -77,4 +78,11 @@ gcf::HttpResponse tutorial_cloud_bigtable(gcf::HttpRequest request) { // NOLINT
.set_header("content-type", "text/plain")
.set_payload(std::move(os).str());
}

} // namespace

gcf::Function tutorial_cloud_bigtable() {
return gcf::MakeFunction(handle_request);
}

// [END bigtable_functions_quickstart]
15 changes: 10 additions & 5 deletions examples/site/tutorial_cloud_spanner/tutorial_cloud_spanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
// limitations under the License.

// [START spanner_functions_quickstart]
#include <google/cloud/functions/http_request.h>
#include <google/cloud/functions/http_response.h>
#include <google/cloud/functions/function.h>
#include <google/cloud/spanner/client.h>
#include <iostream>
#include <sstream>
Expand All @@ -25,6 +24,7 @@ namespace gcf = ::google::cloud::functions;
namespace spanner = ::google::cloud::spanner;

namespace {

auto get_spanner_database() {
auto getenv = [](char const* var) {
auto const* value = std::getenv(var);
Expand All @@ -38,10 +38,8 @@ auto get_spanner_database() {
getenv("SPANNER_INSTANCE"),
getenv("SPANNER_DATABASE"));
}
} // namespace

gcf::HttpResponse tutorial_cloud_spanner(
gcf::HttpRequest /*request*/) { // NOLINT
gcf::HttpResponse handle_request(gcf::HttpRequest const& /*request*/) {
static auto const kClient =
spanner::Client(spanner::MakeConnection(get_spanner_database()));

Expand All @@ -62,4 +60,11 @@ gcf::HttpResponse tutorial_cloud_spanner(
.set_header("content-type", "text/plain")
.set_payload(std::move(os).str());
}

} // namespace

gcf::Function tutorial_cloud_spanner() {
return gcf::MakeFunction(handle_request);
}

// [END spanner_functions_quickstart]