@@ -16,7 +16,6 @@ package bigquery
16
16
17
17
import (
18
18
"context"
19
- "errors"
20
19
"fmt"
21
20
"io"
22
21
"net/http"
@@ -25,12 +24,12 @@ import (
25
24
"time"
26
25
27
26
"cloud.google.com/go/internal"
27
+ "cloud.google.com/go/internal/detect"
28
28
"cloud.google.com/go/internal/version"
29
29
gax "github.com/googleapis/gax-go/v2"
30
30
bq "google.golang.org/api/bigquery/v2"
31
31
"google.golang.org/api/googleapi"
32
32
"google.golang.org/api/option"
33
- "google.golang.org/api/transport"
34
33
)
35
34
36
35
const (
@@ -83,11 +82,10 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio
83
82
return nil , fmt .Errorf ("bigquery: constructing client: %v" , err )
84
83
}
85
84
86
- if projectID == DetectProjectID {
87
- projectID , err = detectProjectID (ctx , opts ... )
88
- if err != nil {
89
- return nil , fmt .Errorf ("failed to detect project: %v" , err )
90
- }
85
+ // Handle project autodetection.
86
+ projectID , err = detect .ProjectID (ctx , projectID , "" , opts ... )
87
+ if err != nil {
88
+ return nil , err
91
89
}
92
90
93
91
c := & Client {
@@ -110,17 +108,6 @@ func (c *Client) Close() error {
110
108
return nil
111
109
}
112
110
113
- func detectProjectID (ctx context.Context , opts ... option.ClientOption ) (string , error ) {
114
- creds , err := transport .Creds (ctx , opts ... )
115
- if err != nil {
116
- return "" , fmt .Errorf ("fetching creds: %v" , err )
117
- }
118
- if creds .ProjectID == "" {
119
- return "" , errors .New ("credentials did not provide a valid ProjectID" )
120
- }
121
- return creds .ProjectID , nil
122
- }
123
-
124
111
// Calls the Jobs.Insert RPC and returns a Job.
125
112
func (c * Client ) insertJob (ctx context.Context , job * bq.Job , media io.Reader ) (* Job , error ) {
126
113
call := c .bqs .Jobs .Insert (c .projectID , job ).Context (ctx )
0 commit comments