Workflows API용 Cloud 클라이언트 라이브러리 시작하기

Workflows용 Cloud 클라이언트 라이브러리를 시작하는 방법을 보여줍니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

C++

이 샘플을 사용해 보기 전에 Workflows 빠른 시작: 클라이언트 라이브러리 사용C++ 설정 안내를 따르세요.

Workflows에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

#include "google/cloud/workflows/v1/workflows_client.h"
#include "google/cloud/location.h"
#include <iostream>

int main(int argc, char* argv[]) try {
  if (argc != 3) {
    std::cerr << "Usage: " << argv[0] << " project-id location-id\n";
    return 1;
  }

  auto const location = google::cloud::Location(argv[1], argv[2]);

  namespace workflows = ::google::cloud::workflows_v1;
  auto client =
      workflows::WorkflowsClient(workflows::MakeWorkflowsConnection());

  for (auto w : client.ListWorkflows(location.FullName())) {
    if (!w) throw std::move(w).status();
    std::cout << w->DebugString() << "\n";
  }

  return 0;
} catch (google::cloud::Status const& status) {
  std::cerr << "google::cloud::Status thrown: " << status << "\n";
  return 1;
}

Node.js

이 샘플을 사용해 보기 전에 Workflows 빠른 시작: 클라이언트 라이브러리 사용Node.js 설정 안내를 따르세요. 자세한 내용은 Workflows Node.js API 참고 문서를 참조하세요.

Workflows에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

const {WorkflowsClient} = require('@google-cloud/workflows');
const client = new WorkflowsClient();

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const location = 'us-central1';

async function listWorkflows(projectId, location) {
  const [workflows] = await client.listWorkflows({
    parent: client.locationPath(projectId, location),
  });
  for (const workflow of workflows) {
    console.info(`name: ${workflow.name}`);
  }
}

listWorkflows(projectId, location).catch(err => {
  console.error(err.message);
  process.exitCode = 1;
});

Node.js

이 샘플을 사용해 보기 전에 Workflows 빠른 시작: 클라이언트 라이브러리 사용의 Node.js 설정 안내를 따르세요. 자세한 내용은 Workflows Node.js API 참조 문서를 확인하세요.

Workflows에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import {WorkflowsClient} from '@google-cloud/workflows';
const client = new WorkflowsClient();

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const location = 'us-central1';

async function listWorkflows(projectId: string, location: string) {
  const [workflows] = await client.listWorkflows({
    parent: client.locationPath(projectId, location),
  });
  for (const workflow of workflows) {
    console.info(`name: ${workflow.name}`);
  }
}

listWorkflows(projectId, location).catch((err: Error) => {
  console.error(err.message);
  process.exitCode = 1;
});

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저 참조하기