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 the Go setup instructions in the BigQuery quickstart using client libraries . For more information, see the BigQuery Go API reference documentation .

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set 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. 
 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

Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries . For more information, see the BigQuery Node.js API reference documentation .

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

  // 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 
 ); 
 } 
 

What's next

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

Design a Mobile Site
View Site in Mobile | Classic
Share by: