サービス エンドポイントの設定

このサンプルは、BigQuery クライアント ライブラリの使用時に代替エンドポイントを設定する方法を示します。

コードサンプル

Go

このサンプルを試す前に、クライアント ライブラリを使用した BigQuery クイックスタートGo の手順に沿って設定を行ってください。詳細については、BigQuery Go API のリファレンス ドキュメントをご覧ください。

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

import (
	"context"
	"fmt"

	"cloud.google.com/go/bigquery"
	"google.golang.org/api/option"
)

// setClientEndpoint creates a bigquery.Client pointing
// to a specific endpoint.
func setClientEndpoint(endpoint, projectID string) (*bigquery.Client, error) {
	// projectID := "my-project-id"
	// endpoint := "https://bigquery.googleapis.com/bigquery/v2/
	ctx := context.Background()
	client, err := bigquery.NewClient(ctx, projectID, option.WithEndpoint(endpoint))
	if err != nil {
		return nil, fmt.Errorf("bigquery.NewClient: %w", err)
	}
	defer client.Close()

	return client, nil
}

Node.js

このサンプルを試す前に、クライアント ライブラリを使用した BigQuery クイックスタートNode.js の手順に沿って設定を行ってください。詳細については、BigQuery Node.js API のリファレンス ドキュメントをご覧ください。

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

// Import the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');

function setClientEndpoint() {
  // Create a bigquery client pointing to a specific endpoint

  /**
   * TODO(developer): Uncomment the following line of code and fill in your region before running the sample.
   */
  // const region = 'my-region';

  const bigquery = new BigQuery({
    apiEndpoint: `${region}-bigquery.googleapis.com`,
  });

  console.log('API Endpoint:');
  console.log(bigquery.apiEndpoint);
}

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。