fixed default credentials

This commit is contained in:
Mads Schou-Andreasen 2020-05-22 10:03:55 +02:00
parent 846386c7ff
commit cf757802a3

View File

@ -7,7 +7,6 @@ import (
"fmt"
"github.com/streadway/amqp"
"google.golang.org/api/option"
"os"
"sync"
"time"
)
@ -56,21 +55,17 @@ func (conn *PubSubConn) Send(msg string) error {
if conn.svc == nil {
var creds option.ClientOption
var svc *pubsub.Client
var err error
credPath := conn.ep.PubSub.CredPath
if credPath != "" {
creds = option.WithCredentialsFile(credPath)
svc, err = pubsub.NewClient(ctx, conn.ep.PubSub.Project, creds)
} else {
envCredPath := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
creds = option.WithCredentialsFile(credPath)
if envCredPath == "" {
fmt.Println(errMissingGoogleCredentials)
return errMissingGoogleCredentials
}
svc, err = pubsub.NewClient(ctx, conn.ep.PubSub.Project)
}
svc, err := pubsub.NewClient(ctx, conn.ep.PubSub.Project, creds)
if err != nil {
fmt.Println(err)
return err