set the service endpoint

This sample demonstrates how to set an alternate endpoint when using the BigQuery client libraries.

Code sample

Go

Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""cloud.google.com/go/bigquery""google.golang.org/api/option")// setClientEndpoint creates a bigquery.Client pointing// to a specific endpoint.funcsetClientEndpoint(endpoint,projectIDstring)(*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))iferr!=nil{returnnil,fmt.Errorf("bigquery.NewClient: %w",err)}deferclient.Close()returnclient,nil}

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

// Import the Google Cloud client libraryconst{BigQuery}=require('@google-cloud/bigquery');functionsetClientEndpoint(){// 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';constbigquery=newBigQuery({apiEndpoint:`${region}-bigquery.googleapis.com`,});console.log('API Endpoint:');console.log(bigquery.apiEndpoint);}

What's next

To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.