Skip to content

Commit db15206

Browse files
committed
ran go fmt
1 parent 1c6ea47 commit db15206

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

cmd/cloud_sql_proxy/cloud_sql_proxy.go

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ can be removed automatically by this program.`)
8181
token = flag.String("token", "", "When set, the proxy uses this Bearer token for authorization.")
8282
tokenFile = flag.String("credential_file", "", `If provided, this json file will be used to retrieve Service Account credentials.
8383
You may set the GOOGLE_APPLICATION_CREDENTIALS environment variable for the same effect.`)
84-
85-
// Set when gcloud execution failed.
86-
gcloudErrStr string
8784

85+
// Set when gcloud execution failed.
86+
gcloudErrStr string
8887
)
8988

9089
const (
@@ -332,36 +331,36 @@ func listInstances(ctx context.Context, cl *http.Client, projects []string) ([]s
332331
}
333332

334333
func gcloudProject() []string {
335-
const gcloudResultErrStr = "gcloud failed to get project list. See log for detail."
336-
buf := new(bytes.Buffer)
337-
cmd := exec.Command("gcloud", "--format", "json", "config", "list", "core/project")
338-
cmd.Stdout = buf
339-
340-
if err := cmd.Run(); err != nil {
341-
if strings.Contains(err.Error(), "executable file not found") {
342-
gcloudErrStr = "gcloud could not be found in the system path"
343-
return nil
344-
}
345-
gcloudErrStr = gcloudResultErrStr
346-
logging.Errorf("Error detecting gcloud project: %v", err)
347-
return nil
348-
}
349-
350-
var data struct {
351-
Core struct {
352-
Project string
353-
}
354-
}
355-
356-
if err := json.Unmarshal(buf.Bytes(), &data); err != nil {
357-
gcloudErrStr = gcloudResultErrStr
358-
logging.Errorf("Failed to unmarshal bytes from gcloud: %v", err)
359-
logging.Errorf(" gcloud returned:\n%s", buf)
360-
return nil
361-
}
362-
363-
logging.Infof("Using gcloud's active project: %v", data.Core.Project)
364-
return []string{data.Core.Project}
334+
const gcloudResultErrStr = "gcloud failed to get project list. See log for detail."
335+
buf := new(bytes.Buffer)
336+
cmd := exec.Command("gcloud", "--format", "json", "config", "list", "core/project")
337+
cmd.Stdout = buf
338+
339+
if err := cmd.Run(); err != nil {
340+
if strings.Contains(err.Error(), "executable file not found") {
341+
gcloudErrStr = "gcloud could not be found in the system path"
342+
return nil
343+
}
344+
gcloudErrStr = gcloudResultErrStr
345+
logging.Errorf("Error detecting gcloud project: %v", err)
346+
return nil
347+
}
348+
349+
var data struct {
350+
Core struct {
351+
Project string
352+
}
353+
}
354+
355+
if err := json.Unmarshal(buf.Bytes(), &data); err != nil {
356+
gcloudErrStr = gcloudResultErrStr
357+
logging.Errorf("Failed to unmarshal bytes from gcloud: %v", err)
358+
logging.Errorf(" gcloud returned:\n%s", buf)
359+
return nil
360+
}
361+
362+
logging.Infof("Using gcloud's active project: %v", data.Core.Project)
363+
return []string{data.Core.Project}
365364
}
366365

367366
// Main executes the main function of the proxy, allowing it to be called from tests.

cmd/cloud_sql_proxy/proxy.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,19 @@ func CreateInstanceConfigs(dir string, useFuse bool, instances []string, instanc
337337
return nil, nil
338338
}
339339
// FUSE disabled.
340-
if len(instances) == 0 && instancesSrc == "" {
341-
var flags string
342-
if fuse.Supported() {
343-
flags = "-projects, -fuse, or -instances"
344-
} else {
345-
flags = "-projects or -instances"
346-
}
347-
348-
errStr := fmt.Sprintf("no instance selected because none of %s is specified", flags)
349-
if gcloudErrStr != "" {
350-
errStr = fmt.Sprintf("%s and %s", errStr, gcloudErrStr)
351-
}
352-
return nil, errors.New(errStr)
353-
}
340+
if len(instances) == 0 && instancesSrc == "" {
341+
var flags string
342+
if fuse.Supported() {
343+
flags = "-projects, -fuse, or -instances"
344+
} else {
345+
flags = "-projects or -instances"
346+
}
347+
348+
errStr := fmt.Sprintf("no instance selected because none of %s is specified", flags)
349+
if gcloudErrStr != "" {
350+
errStr = fmt.Sprintf("%s and %s", errStr, gcloudErrStr)
351+
}
352+
return nil, errors.New(errStr)
353+
}
354354
return cfgs, nil
355355
}

0 commit comments

Comments
 (0)