### Datastore Client Quickstart Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/datastore/README.md A 'Hello World' program demonstrating how to create a Datastore client, construct a key and mutation, and commit a change. This example is suitable for getting started with the library in a larger project. ```cc #include "google/cloud/datastore/v1/datastore_client.h" #include int main(int argc, char* argv[]) try { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " project-id\n"; return 1; } namespace datastore = ::google::cloud::datastore_v1; auto client = datastore::DatastoreClient(datastore::MakeDatastoreConnection()); auto const* project_id = argv[1]; google::datastore::v1::Key key; key.mutable_partition_id()->set_project_id(project_id); auto& path = *key.add_path(); path.set_kind("Task"); path.set_name("sampletask1"); google::datastore::v1::Mutation mutation; auto& upsert = *mutation.mutable_upsert(); *upsert.mutable_key() = key; google::datastore::v1::Value value; value.set_string_value("Buy milk"); upsert.mutable_properties()->insert({"description", std::move(value)}); auto put = client.Commit( project_id, google::datastore::v1::CommitRequest::NON_TRANSACTIONAL, {mutation}); if (!put) throw std::move(put).status(); std::cout << "Saved " << key.DebugString() << " " << put->DebugString() << "\n"; return 0; } catch (google::cloud::Status const& status) { std::cerr << "google::cloud::Status thrown: " << status << "\n"; return 1; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/osconfig/doc/main.dox A quickstart example demonstrating the usage of the OS Config API C++ client library. ```cpp #include "google/cloud/osconfig/quickstart/quickstart.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const instance_id = argv[2]; auto client = google::cloud::osconfig_v1::OsConfigServiceClient( google::cloud::osconfig_v1::MakeOsConfigServiceClient()); google::cloud::osconfig_v1::ListOSPolicyAssignmentReportsRequest request; request.set_parent(std::string("projects/") + project_id + "/instances/" + instance_id); std::cout << "OS Policy Assignment Reports:\n"; for (auto osconfigreport : client.ListOSPolicyAssignmentReports(request)) { if (!osconfigreport) { break; } std::cout << osconfigreport->DebugString() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/servicemanagement/doc/main.dox A quickstart example demonstrating the use of the Service Management API C++ client library. ```cpp #include "google/cloud/servicemanagement/v1/service_manager_client.h" #include "google/cloud/testing/mock_safe_calls_log.h" #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; // Create a client auto client = google::cloud::servicemanagement_v1::ServiceManagerClient( google::cloud::servicemanagement_v1::MakeServiceManagerConnection()); // Initialize request argument(s) google::api::servicecontrol::v1::ListServicesRequest request; request.set_producer_project_id(project_id); // Make the request for (auto service : client.ListServices(request)) { if (!service) { std::cerr << "Error making ListServices request: " << service.status() << "\n"; return 1; } std::cout << "Service name: " << service->DebugString() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/devicestreaming/doc/main.dox A quickstart example demonstrating the usage of the Device Streaming API C++ client library. ```cpp #include "google/cloud/devicestreaming/v1/device_streaming_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; // Create a client google::cloud::devicestreaming_v1::DeviceStreamingClient client( google::cloud::devicestreaming_v1::MakeDeviceStreamingClient()); // Initialize request argument(s) google::cloud::devicestreaming_v1::ListDevicesRequest request; request.set_parent( std::string("projects/") + project_id + "/locations/" + location); // Make the request for (auto dev = client.ListDevices(request.get()); dev.has_value(); ++dev) { std::cout << "Received: " << dev->DebugString() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/deploy/doc/main.dox A quickstart example demonstrating the usage of the Google Cloud Deploy API C++ client library. ```cpp #include "google/cloud/deploy/v1/cloud_deploy_client.h" #include "google/cloud/deploy/v1/cloud_deploy_connection.h" #include "google/cloud/deploy/v1/cloud_deploy_options.h" #include "google/cloud/deploy/v1/internal/cloud_deploy_rest_stub.h" #include "google/cloud/deploy/v1/internal/cloud_deploy_stub.h" #include "google/cloud/deploy/v1/internal/cloud_deploy_stub_factory.h" #include "google/cloud/deploy/v1/internal/cloud_deploy_tracing_connection.h" #include "google/cloud/deploy/v1/internal/cloud_deploy_tracing_stub.h" #include "google/cloud/deploy/v1/internal/cloud_deploy_tracing_stub_factory.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_logging_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_metadata_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_rest_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_rest_logging_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_rest_metadata_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_rest_tracing_connection.h" #include "google/cloud/deploy/v1/internal/default_cloud_deploy_tracing_connection.h" #include "google/cloud/deploy/v1/internal/rest_options.h" #include "google/cloud/deploy/v1/internal/rest_response.h" #include "google/cloud/deploy/v1/internal/rest_utility.h" #include "google/cloud/deploy/v1/internal/rest_version.h" #include "google/cloud/deploy/v1/internal/service_endpoint.h" #include "google/cloud/deploy/v1/internal/service_endpoint_impl.h" #include "google/cloud/deploy/v1/internal/service_endpoint_rest.h" #include "google/cloud/deploy/v1/internal/service_endpoint_rest_impl.h" #include "google/cloud/deploy/v1/internal/service_endpoint_rest_options.h" #include "google/cloud/deploy/v1/internal/service_endpoint_rest_utility.h" #include "google/cloud/deploy/v1/internal/service_endpoint_rest_version.h" #include "google/cloud/deploy/v1/internal/service_endpoint_tracing_connection.h" #include "google/cloud/deploy/v1/internal/service_endpoint_tracing_stub.h" #include "google/cloud/deploy/v1/internal/service_endpoint_tracing_stub_factory.h" #include "google/cloud/deploy/v1/internal/service_endpoint_tracing_utility.h" #include "google/cloud/deploy/v1/internal/service_endpoint_utility.h" #include "google/cloud/deploy/v1/internal/service_endpoint_version.h" #include "google/cloud/deploy/v1/internal/tracing_options.h" #include "google/cloud/deploy/v1/internal/tracing_stub.h" #include "google/cloud/deploy/v1/internal/tracing_stub_factory.h" #include "google/cloud/deploy/v1/internal/tracing_utility.h" #include "google/cloud/deploy/v1/internal/version.h" #include "google/cloud/deploy/v1/cloud_deploy_connection.h" #include "google/cloud/deploy/v1/cloud_deploy_options.h" #include "google/cloud/deploy/v1/cloud_deploy_client.h" #include "google/cloud/deploy/v1/cloud_deploy_rest_stub.h" #include "google/cloud/deploy/v1/cloud_deploy_stub.h" #include "google/cloud/deploy/v1/cloud_deploy_stub_factory.h" #include "google/cloud/deploy/v1/cloud_deploy_tracing_connection.h" #include "google/cloud/deploy/v1/cloud_deploy_tracing_stub.h" #include "google/cloud/deploy/v1/cloud_deploy_tracing_stub_factory.h" #include "google/cloud/deploy/v1/default_cloud_deploy_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_logging_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_metadata_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_rest_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_rest_logging_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_rest_metadata_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_rest_tracing_connection.h" #include "google/cloud/deploy/v1/default_cloud_deploy_tracing_connection.h" #include "google/cloud/deploy/v1/rest_options.h" #include "google/cloud/deploy/v1/rest_response.h" #include "google/cloud/deploy/v1/rest_utility.h" #include "google/cloud/deploy/v1/rest_version.h" #include "google/cloud/deploy/v1/service_endpoint.h" #include "google/cloud/deploy/v1/service_endpoint_impl.h" #include "google/cloud/deploy/v1/service_endpoint_rest.h" #include "google/cloud/deploy/v1/service_endpoint_rest_impl.h" #include "google/cloud/deploy/v1/service_endpoint_rest_options.h" #include "google/cloud/deploy/v1/service_endpoint_rest_utility.h" #include "google/cloud/deploy/v1/service_endpoint_rest_version.h" #include "google/cloud/deploy/v1/service_endpoint_tracing_connection.h" #include "google/cloud/deploy/v1/service_endpoint_tracing_stub.h" #include "google/cloud/deploy/v1/service_endpoint_tracing_stub_factory.h" #include "google/cloud/deploy/v1/service_endpoint_tracing_utility.h" #include "google/cloud/deploy/v1/service_endpoint_utility.h" #include "google/cloud/deploy/v1/service_endpoint_version.h" #include "google/cloud/deploy/v1/tracing_options.h" #include "google/cloud/deploy/v1/tracing_stub.h" #include "google/cloud/deploy/v1/tracing_stub_factory.h" #include "google/cloud/deploy/v1/tracing_utility.h" #include "google/cloud/deploy/v1/version.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; // Create a client google::cloud::deploy_v1::CloudDeployClient client( google::cloud::deploy_v1::MakeCloudDeployConnection()); // Initialize request argument(s) google::cloud::deploy_v1::ListDeliveryPipelinesRequest request; request.set_parent(std::string("projects/") + project_id + "/locations/" + location); // Make the request for (auto pipeline : client.ListDeliveryPipelines(request)) { if (!pipeline) { std::cerr << "Error making ListDeliveryPipelines request: " << pipeline.status() << "\n"; return 1; } std::cout << "Pipeline: " << pipeline->name() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/parametermanager/doc/main.dox A quickstart example demonstrating the basic usage of the Parameter Manager API C++ client library. ```cpp #include #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; // Create a client google::cloud::parametermanager_v1::ParameterManagerClient client( google::cloud::MakeParameterManagerConnection()); // Build the name for the parent resource auto parent = google::cloud::parametermanager_v1::LocationName( project_id, location); // List parameters std::cout << "Listing parameters in " << parent << "\n"; for (auto p : client.ListParameters(parent.FullName())) { if (!p) { std::cerr << "Error listing parameters: " << p.status() << "\n"; break; } std::cout << "- " << p->name() << "\ "; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/securitycentermanagement/doc/main.dox A quickstart example demonstrating the usage of the Security Center Management API C++ client library. ```cpp #include "google/cloud/securitycentermanagement/v1/security_center_management_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } auto const project_id = std::string(argv[1]); auto const location = std::string(argv[2]); google::cloud::securitycentermanagement_v1::SecurityCenterManagementClient client( google::cloud::MakeSecurityCenterManagementConnection()); auto org_id = google::cloud::Location(project_id, location).FullName(); for (auto sc : client.ListSecurityCenterConfigs( google::cloud::securitycentermanagement_v1::ListSecurityCenterConfigsRequest{ .parent = org_id})) { if (!sc.ok()) { std::cerr << "Error fetching security center configs: " << sc.status() << "\n"; break; } std::cout << "Security Center Config: " << sc->DebugString() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/hypercomputecluster/doc/main.dox A quickstart example demonstrating the usage of the Cluster Director API C++ client library. ```cpp #include "google/cloud/hypercomputecluster/v1/hypercompute_cluster_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; // Create a client google::cloud::hypercomputecluster_v1::HypercomputeClusterClient client( google::cloud::MakeDefaultCredentials()); // List locations for (auto loc : client.ListLocations(project_id, location).page_result()) { if (!loc) { std::cerr << "Error listing locations: " << loc.status() << "\n"; return 1; } std::cout << "Location: " << loc->name() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/trace/doc/main.dox A quickstart example demonstrating the usage of the Cloud Trace API C++ client library. ```cpp #include "google/cloud/trace/v1/trace_client.h" #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; auto client = google::cloud::trace_v1::TraceServiceClient( google::cloud::MakeTraceServiceConnection()); google::devtools::cloudtrace::v1::ListTracesRequest request; request.set_project_id(project_id); auto response = client.ListTraces(request); if (!response) { std::cerr << "Error making request: " << response.status().message() << "\n"; return 1; } for (auto const& trace : response->traces()) { std::cout << trace.id() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/confidentialcomputing/doc/main.dox A quickstart example demonstrating the usage of the Confidential Computing API C++ client library. ```cpp #include "google/cloud/confidentialcomputing/v1/confidential_computing_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; // Create a client google::cloud::confidentialcomputing_v1::ConfidentialComputingClient client( google::cloud::MakeConfidentialComputingConnection()); // Initialize request argument(s) google::cloud::ListServiceAccountsRequest list_request; list_request.set_parent(std::string("projects/") + project_id + "/locations/" + location); // Make the request for (auto sa : client.ListServiceAccounts(list_request).items()) { std::cout << "Service Account: " << sa.DebugString() << std::endl; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/auditmanager/doc/main.dox A quickstart example demonstrating the usage of the Audit Manager API C++ client library. ```cpp #include "google/cloud/auditmanager/v1/audit_manager_client.h" #include "google/cloud/testing/mock_audit_manager_connection.h" #include #include #include namespace google { namespace cloud { namespace auditmanager_v1 { namespace { using ::testing::_; // Mock connection for testing. class MockAuditManagerConnection : public auditmanager_v1::MockAuditManagerConnection { public: MOCK_METHOD(StatusOr, ListEnvironments, (google::cloud::auditmanager::v1::ListEnvironmentsRequest const& request), (override)); }; void RunIfSuccessful(StatusOr response) { if (response.ok()) { // Process the successful response. } } } // namespace } } } int main(int argc, char* argv[]) { // Example of how to create a client and call an RPC. auto client = google::cloud::auditmanager_v1::AuditManagerClient( google::cloud::auditmanager_v1::MakeAuditManagerConnection()); google::cloud::auditmanager::v1::ListEnvironmentsRequest request; request.set_parent("projects/my-project/locations/us-central1"); auto response = client.ListEnvironments(request); RunIfSuccessful(std::move(response)); return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/workflows/doc/main.dox A quickstart example demonstrating the usage of the Workflow Executions API C++ client library. ```cpp #include "google/cloud/workflows/executions/v1/executions_client.h" #include "google/cloud/testing/mock_workflows_executions_v1.h" #include #include namespace { using ::google::cloud::testing_util::IsOkAndHolds; using ::google::cloud::workflows_executions_v1::ExecutionsClient; using ::google::cloud::workflows_executions_v1::ListExecutionsRequest; using ::google::cloud::workflows_executions_v1::ListExecutionsResponse; using ::testing::_; using ::testing::Return; TEST(WorkflowsExecutionsTest, ListExecutions) { auto mock = std::make_unique< ::testing::MockWorkflowsExecutionsConnection>(); EXPECT_CALL(*mock, ListExecutions(_, _)) .Times(1) .WillOnce(Return(std::vector{})); auto client = std::make_unique(std::move(mock)); std::string const name = "projects/my-project/locations/us-central1/workflows/my-workflow"; auto response = client->ListExecutions(name); EXPECT_THAT(response, IsOkAndHolds(testing::IsEmpty())); } } // namespace ``` -------------------------------- ### Quickstart: List Domains C++ Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/managedidentities/README.md A "Hello World" program demonstrating how to list Active Directory domains in a specified project and location. Ensure you have the library built and installed before running. ```cc #include "google/cloud/managedidentities/v1/managed_identities_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) try { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " project-id\n"; return 1; } auto const location = google::cloud::Location(argv[1], "global"); namespace managedidentities = ::google::cloud::managedidentities_v1; auto client = managedidentities::ManagedIdentitiesServiceClient( managedidentities::MakeManagedIdentitiesServiceConnection()); for (auto d : client.ListDomains(location.FullName())) { if (!d) throw std::move(d).status(); std::cout << d->DebugString() << "\n"; } return 0; } catch (google::cloud::Status const& status) { std::cerr << "google::cloud::Status thrown: " << status << "\n"; return 1; } ``` -------------------------------- ### Quickstart: All Examples Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/storage/doc/storage-main.dox A "Hello World" program demonstrating how to incorporate the library into your project. ```cpp #include "google/cloud/storage/client.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } google::cloud::storage::Client client; auto reader = client.ReadObject(argv[1], argv[2]); if (!reader) { std::cerr << "Error reading object: " << reader.status().message() << std::endl; return 1; } for (auto const& line : reader.value()) { std::cout << line; } return 0; } ``` -------------------------------- ### Compile BigQuery Quickstart with Bazel Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/bigquery/quickstart/README.md Use Bazel to compile the BigQuery quickstart example. Ensure you are in the quickstart directory and have Bazel installed. ```bash cd $HOME/google-cloud-cpp/google/cloud/bigquery/quickstart bazel build ... ``` -------------------------------- ### Install BackupDR with vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/backupdr/quickstart/README.md Install the google-cloud-cpp library with BackupDR support using vcpkg. This is a prerequisite for using CMake to build the quickstart example. ```bash cd $HOME/vcpkg ./vcpkg install google-cloud-cpp[core,backupdr] ``` -------------------------------- ### Install Dependencies with vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/config/quickstart/README.md This command installs the google-cloud-cpp library and its core and config components using vcpkg. This is an example setup step when using CMake. ```bash cd $HOME/vcpkg ./vcpkg install google-cloud-cpp[core,config] ``` -------------------------------- ### Compile VPC Access C++ Quickstart with Bazel Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/vpcaccess/quickstart/README.md Use this command to compile the quickstart example after installing Bazel. Bazel handles dependency downloads and compilation. ```bash cd $HOME/google-cloud-cpp/google/cloud/vpcaccess/quickstart bazel build ... ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/storagetransfer/doc/main.dox A basic example demonstrating the usage of the Storage Transfer API C++ client library. ```cpp #include "google/cloud/storage_transfer/v1/storage_transfer_client.h" #include "google/cloud/storage_transfer/v1/storage_transfer_connection.h" #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/log.h" #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; namespace storagetransfer = ::google::cloud::storage_transfer_v1; auto client = storagetransfer::StorageTransferServiceClient( storagetransfer::MakeStorageTransferServiceConnectionHomeRegion( google::cloud::Options{}.set_principal_selector( project_id))); google::storagetransfer::v1::ListAgentsRequest request; request.set_parent("projects/" + project_id + "/agentPools/default"); auto agents = client.ListAgents(request); if (!agents) { std::cerr << "Error listing agents: " << agents.status().message() << std::endl; return 1; } for (auto const& agent : agents->agents()) { std::cout << "Agent name: " << agent.id() << std::endl; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/memcache/doc/main.dox A basic example demonstrating the usage of the Cloud Memorystore for Memcached API C++ client library. ```cpp #include "google/cloud/memcache/v1/cloud_memcache_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const region = argv[2]; // Create a client google::cloud::memcache_v1::CloudMemcacheClient client( google::cloud::MakeCloudMemcacheConnection()); // List instances in a location for (auto instance : client.ListInstances( google::cloud::Location(project_id, region).FullName(), google::cloud::Args(google::cloud::consumer_projects::WithParent(project_id)))) { if (!instance) { std::cerr << "Error listing instances: " << instance.status() << "\n"; break; } std::cout << "Instance: " << instance->DebugString() << "\n"; } return 0; } ``` -------------------------------- ### Compile AutoML C++ Quickstart with Bazel Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/automl/quickstart/README.md Use this command to compile the quickstart example after installing Bazel. Bazel handles dependency downloads and compilation automatically. ```bash cd $HOME/google-cloud-cpp/google/cloud/automl/quickstart bazel build ... ``` -------------------------------- ### Install Access Approval Dependencies with vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/accessapproval/quickstart/README.md Install the Access Approval C++ library and its core dependencies using vcpkg. This is an example setup step for CMake. ```bash cd $HOME/vcpkg ./vcpkg install google-cloud-cpp[core,accessapproval] ``` -------------------------------- ### Configure and Build GKE Recommender C++ Quickstart with CMake Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/gkerecommender/quickstart/README.md Configure the CMake build system for the quickstart example, specifying the vcpkg toolchain file, and then build the project. This command assumes you have vcpkg installed and have already installed the required packages. ```bash cd $HOME/google-cloud-cpp/google/cloud/gkerecommender/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Quickstart: List Configurations Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/licensemanager/README.md A "Hello World" program demonstrating how to list configurations using the License Manager API client. Ensure you have the correct project ID as a command-line argument. ```cc #include "google/cloud/licensemanager/v1/license_manager_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) try { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " project-id\n"; return 1; } auto const location = google::cloud::Location(argv[1], "-"); namespace licensemanager = ::google::cloud::licensemanager_v1; auto client = licensemanager::LicenseManagerClient( licensemanager::MakeLicenseManagerConnection()); for (auto r : client.ListConfigurations(location.FullName())) { if (!r) throw std::move(r).status(); std::cout << r->DebugString() << "\n"; } return 0; } catch (google::cloud::Status const& status) { std::cerr << "google::cloud::Status thrown: " << status << "\n"; return 1; } ``` -------------------------------- ### Install Pub/Sub Lite Dependencies with vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/pubsublite/quickstart/README.md This command installs the google-cloud-cpp library with Pub/Sub Lite support using vcpkg. This is a prerequisite for building the quickstart example with CMake. ```bash cd $HOME/vcpkg ./vcpkg install google-cloud-cpp[core,pubsublite] ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/datamigration/doc/main.dox This snippet demonstrates a basic usage of the Database Migration API C++ client library. ```cpp #include "google/cloud/datamigration/v1/data_migration_client.h" #include "google/cloud/datamigration/v1/data_migration_connection.h" #include "google/cloud/common_options.h" #include "google/cloud/log.h" #include #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; try { auto client = google::cloud::datamigration_v1::DataMigrationServiceClient( google::cloud::datamigration_v1::MakeDataMigrationServiceConnection( google::cloud::Options{}.set( google::auth::Credentials())) ); // List databases in the project. google::cloud::datamigration_v1::ListDatabasesRequest request; request.set_parent(std::string("projects/") + project_id + "/locations/us-central1"); std::cout << "Listing databases:\n"; for (auto db : client.ListDatabases(request)) { if (!db) { throw std::runtime_error(db.status().message()); } std::cout << "- " << db->name() << "\n"; } } catch (google::cloud::Status const& status) { std::cerr << "Error creating client: " << status.message() << std::endl; return 1; } catch (std::exception const& ex) { std::cerr << "Error: " << ex.what() << std::endl; return 1; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/parallelstore/doc/main.dox A basic example demonstrating the usage of the Parallelstore API C++ client library. ```cpp #include "google/cloud/parallelstore/v1/parallelstore_client.h" #include "google/cloud/testing/mock_async_response_writer.h" #include namespace { void PrintResponse(google::cloud::parallelstore::v1::ListInstancesResponse const& response) { for (auto const& instance : response.instances()) { std::cout << "Instance name: " << instance.name() << std::endl; } } } // namespace int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } google::cloud::parallelstore::v1::ParallelstoreClient client( google::cloud::parallelstore::v1::MakeParallelstoreConnection()); google::cloud::parallelstore::v1::ListInstancesRequest request; request.set_parent("projects/"); request.set_parent(argv[1]); auto list_instances_response = client.ListInstances(request); if (!list_instances_response) { std::cerr << "Error listing instances: " << list_instances_response.status().message() << std::endl; return 1; } PrintResponse(*list_instances_response); return 0; } ``` -------------------------------- ### Compile GKE Recommender C++ Quickstart with Bazel Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/gkerecommender/quickstart/README.md Use this command to compile the quickstart example after installing Bazel. Bazel handles dependency downloads and compilation automatically. ```bash cd $HOME/google-cloud-cpp/google/cloud/gkerecommender/quickstart bazel build ... ``` -------------------------------- ### Compile Essential Contacts C++ Quickstart with Bazel Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/essentialcontacts/quickstart/README.md Use this command to compile the quickstart example after installing Bazel. Bazel handles dependency downloads and compilation automatically. ```bash cd $HOME/google-cloud-cpp/google/cloud/essentialcontacts/quickstart bazel build ... ``` -------------------------------- ### Configure and Build Quickstart with CMake Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/managedidentities/quickstart/README.md Configure and build the Managed Identities C++ quickstart example using CMake and vcpkg toolchain. Ensure you have vcpkg installed and the library is set up. ```bash cd $HOME/google-cloud-cpp/google/cloud/managedidentities/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/securesourcemanager/doc/main.dox A basic example demonstrating the usage of the Secure Source Manager API C++ client library. ```cpp #include "google/cloud/securesourcemanager/v1/secure_source_manager_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; auto client = google::cloud::securesourcemanager_v1::SecureSourceManagerClient( google::cloud::MakeSecureSourceManagerConnection()); for (auto repo : client.ListRepositories( google::cloud::Location(project_id, location))) { if (!repo) throw std::runtime_error(repo.status().message()); std::cout << "Repository: " << repo->DebugString() << "\n"; } return 0; } ``` -------------------------------- ### Install Container Analysis Dependencies with vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/containeranalysis/quickstart/README.md This command installs the google-cloud-cpp library with core and containeranalysis components using vcpkg. This is a prerequisite for using CMake to build the quickstart example. ```bash cd $HOME/vcpkg ./vcpkg install google-cloud-cpp[core,containeranalysis] ``` -------------------------------- ### Configure and Build Quickstart with CMake and vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/texttospeech/quickstart/README.md Configure the CMake build system for the quickstart example, specifying the vcpkg toolchain file, and then build the project. This is done after installing dependencies with vcpkg. ```bash cd $HOME/google-cloud-cpp/google/cloud/texttospeech/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/vmwareengine/doc/main.dox A basic example demonstrating the usage of the VMware Engine API C++ client library. ```cpp #include "google/cloud/vmwareengine/v1/vmware_engine_client.h" #include "google/cloud/common_options.h" #include "google/cloud/log.h" #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; // Create a client auto client = google::cloud::vmwareengine_v1::VmwareEngineClient( google::cloud::MakeSharedEtagCapableCredentialFactory()); // Make a request google::cloud::vmwareengine_v1::ListPrivateCloudsRequest request; request.set_parent("projects/" + project_id + "/locations/us-central1"); auto list_response = client.ListPrivateClouds(request); // Handle the response for (auto const& private_cloud : list_response.value()) { std::cout << "Private Cloud: " << private_cloud.name() << "\n"; } return 0; } ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/redis/doc/main.dox A basic example demonstrating the usage of the Google Cloud Memorystore for Redis API C++ client library. ```cpp #include "google/cloud/redis/v1/cloud_redis_client.h" #include "google/cloud/common_options.h" #include "google/cloud/log.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const instance_id = argv[2]; // Create a client using default options. google::cloud::redis_v1::CloudRedisClient client( google::cloud::MakeDefaultCredentials()); // Get the instance. google::cloud::redis_v1::Instance instance; google::cloud::StatusOr instance_status = client.GetInstance(google::cloud::redis_v1::GetInstanceRequest{}); instance_status->set_name(google::cloud::redis_v1::CloudRedisClient::InstancePath( project_id, "us-central1", instance_id)); instance = *instance_status; std::cout << "Instance: " << instance.name() << "\n"; std::cout << " Location: " << instance.location_id() << "\n"; std::cout << " Tier: " << instance.tier() << "\n"; std::cout << " Read replica mode: " << instance.read_replica_mode() << "\n"; return 0; } ``` -------------------------------- ### Configure and Build Quickstart with CMake Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/backupdr/quickstart/README.md Configure and build the BackupDR C++ quickstart example using CMake, specifying the vcpkg toolchain file. This command builds the project after dependencies are installed. ```bash cd $HOME/google-cloud-cpp/google/cloud/backupdr/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Configure and Build with CMake Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/lustre/quickstart/README.md Configure the CMake project and build the quickstart example. Ensure the CMAKE_TOOLCHAIN_FILE points to your vcpkg installation. ```bash cd $HOME/google-cloud-cpp/google/cloud/lustre/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Configure and Build Quickstart with CMake and vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/trace/quickstart/README.md Configure the CMake build for the quickstart example, specifying the vcpkg toolchain file, and then build the project. This command assumes you have installed vcpkg and the google-cloud-cpp libraries. ```bash cd $HOME/google-cloud-cpp/google/cloud/trace/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/gkeconnect/doc/main.dox A basic example demonstrating the usage of the Connect Gateway API C++ client library. ```cpp #include "google/cloud/gkeconnect/gateway/v1/gateway_control_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } std::string const project_id = argv[1]; std::string const location = argv[2]; // Create a client google::cloud::gkeconnect_gateway_v1::GatewayControlClient client( google::cloud::MakeGatewayControlConnection()); // Initialize request argument(s) google::cloud::gkeconnect_gateway_v1::ListScopesRequest request; request.set_parent("projects/" + project_id + "/locations/" + location); // Make the request for (auto scope : client.ListScopes(request)) { if (!scope) { std::cerr << "Error making ListScopes request: " << scope.status() << std::endl; return 1; } std::cout << "Scope: " << scope->DebugString() << std::endl; } return 0; } ``` -------------------------------- ### Configure and Build Quickstart with CMake and vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/financialservices/quickstart/README.md Configure and build the quickstart example using CMake, specifying the vcpkg toolchain file. This command assumes CMake is installed and vcpkg is in your home directory. ```bash cd $HOME/google-cloud-cpp/google/cloud/financialservices/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Quickstart: List Sources Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/vmmigration/README.md A "Hello World" program demonstrating how to list sources using the VM Migration API client. It requires a project ID as a command-line argument. ```cc #include "google/cloud/vmmigration/v1/vm_migration_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) try { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " project-id\n"; return 1; } auto const location = google::cloud::Location(argv[1], "-"); namespace vmmigration = ::google::cloud::vmmigration_v1; auto client = vmmigration::VmMigrationClient(vmmigration::MakeVmMigrationConnection()); for (auto s : client.ListSources(location.FullName())) { if (!s) throw std::move(s).status(); std::cout << s->DebugString() << "\n"; } return 0; } catch (google::cloud::Status const& status) { std::cerr << "google::cloud::Status thrown: " << status << "\n"; return 1; } ``` -------------------------------- ### Configure and Build Quickstart with CMake and vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/apikeys/quickstart/README.md Configure the API Keys C++ quickstart project using CMake and build it. This example assumes dependencies were installed with vcpkg and specifies the toolchain file. ```bash cd $HOME/google-cloud-cpp/google/cloud/apikeys/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Configure and Build Quickstart with CMake and vcpkg Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/functions/quickstart/README.md Configure the project using CMake, specifying the vcpkg toolchain file, and then build the quickstart example. Ensure you replace `$HOME/vcpkg` with your actual vcpkg installation path. ```bash cd $HOME/google-cloud-cpp/google/cloud/functions/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ``` -------------------------------- ### Quickstart Example Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/cloudcontrolspartner/doc/main.dox A quickstart example demonstrating the usage of the Cloud Controls Partner API C++ client library. ```cpp #include "google/cloud/cloudcontrolspartner/v1/cloud_controls_partner_client.h" #include "google/cloud/location.h" #include int main(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; } auto const location = std::string(argv[1]); auto client = google::cloud::cloudcontrolspartner_v1::CloudControlsPartnerCoreClient( google::cloud::MakeCloudControlsPartnerCoreConnection()); for (auto resp : client.ListWorkloads( google::cloud::cloudcontrolspartner_v1::ListWorkloadsRequest{}, google::cloud::Location(location))) { if (!resp) { std::cerr << "Error making ListWorkloads request: " << resp.status() << std::endl; return 1; } std::cout << "Workload name: " << resp->DebugString() << std::endl; } return 0; } ``` -------------------------------- ### Configure and Build Quickstart with CMake Source: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/containeranalysis/quickstart/README.md Configure the CMake build system for the quickstart example, specifying the vcpkg toolchain file, and then build the project. Ensure you replace '$HOME/vcpkg' with the actual path to your vcpkg installation. ```bash cd $HOME/google-cloud-cpp/google/cloud/containeranalysis/quickstart cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build .build ```