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](https://docs.cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries).


For more information, see the
[BigQuery Go API
reference documentation](https://godoc.org/cloud.google.com/go/bigquery).


To authenticate to BigQuery, set up Application Default Credentials.
For more information, see

[Set up authentication for client libraries](https://docs.cloud.google.com/bigquery/docs/authentication#client-libs).

    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
    }

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=bigquery).