Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions snippets/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/db"
"google.golang.org/api/option"
)

// [END authenticate_db_imports]
Expand All @@ -33,11 +32,9 @@ func authenticateWithAdminPrivileges() {
conf := &firebase.Config{
DatabaseURL: "https://databaseName.firebaseio.com",
}
// Fetch the service account key JSON file contents
opt := option.WithCredentialsFile("path/to/serviceAccountKey.json")

// Initialize the app with a service account, granting admin privileges
app, err := firebase.NewApp(ctx, conf, opt)
// Initialize the app with Application Default Credentials, granting admin privileges
app, err := firebase.NewApp(ctx, conf)
if err != nil {
log.Fatalln("Error initializing app:", err)
}
Expand Down Expand Up @@ -67,10 +64,7 @@ func authenticateWithLimitedPrivileges() {
AuthOverride: &ao,
}

// Fetch the service account key JSON file contents
opt := option.WithCredentialsFile("path/to/serviceAccountKey.json")

app, err := firebase.NewApp(ctx, conf, opt)
app, err := firebase.NewApp(ctx, conf)
if err != nil {
log.Fatalln("Error initializing app:", err)
}
Expand Down Expand Up @@ -100,10 +94,7 @@ func authenticateWithGuestPrivileges() {
AuthOverride: &nilMap,
}

// Fetch the service account key JSON file contents
opt := option.WithCredentialsFile("path/to/serviceAccountKey.json")

app, err := firebase.NewApp(ctx, conf, opt)
app, err := firebase.NewApp(ctx, conf)
if err != nil {
log.Fatalln("Error initializing app:", err)
}
Expand Down
6 changes: 3 additions & 3 deletions snippets/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func sendAll(ctx context.Context, client *messaging.Client) {
},
}

br, err := client.SendAll(context.Background(), messages)
br, err := client.SendEach(context.Background(), messages)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function receives a ctx context.Context parameter, but context.Background() is used here. To allow for proper context propagation (for cancellation, deadlines, tracing, etc.), you should use the ctx variable that is passed into the function.

Suggested change
br, err := client.SendEach(context.Background(), messages)
br, err := client.SendEach(ctx, messages)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With this change, the sendAll function has become functionally identical to the existing sendEach function. This introduces code duplication, which can make maintenance more difficult. Please consider refactoring to remove the duplication, for example by removing this function and updating callers to use sendEach.

if err != nil {
log.Fatalln(err)
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func sendMulticast(ctx context.Context, client *messaging.Client) {
Tokens: registrationTokens,
}

br, err := client.SendMulticast(context.Background(), message)
br, err := client.SendEachForMulticast(context.Background(), message)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function receives a ctx context.Context parameter, but context.Background() is used here. To allow for proper context propagation (for cancellation, deadlines, tracing, etc.), you should use the ctx variable that is passed into the function.

Suggested change
br, err := client.SendEachForMulticast(context.Background(), message)
br, err := client.SendEachForMulticast(ctx, message)

if err != nil {
log.Fatalln(err)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func sendMulticastAndHandleErrors(ctx context.Context, client *messaging.Client)
Tokens: registrationTokens,
}

br, err := client.SendMulticast(context.Background(), message)
br, err := client.SendEachForMulticast(context.Background(), message)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function receives a ctx context.Context parameter, but context.Background() is used here. To allow for proper context propagation (for cancellation, deadlines, tracing, etc.), you should use the ctx variable that is passed into the function.

Suggested change
br, err := client.SendEachForMulticast(context.Background(), message)
br, err := client.SendEachForMulticast(ctx, message)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

With this change, the sendMulticastAndHandleErrors function has become functionally identical to the existing sendEachForMulticastAndHandleErrors function. This introduces code duplication. To improve maintainability, please consider removing this function and updating any callers to use sendEachForMulticastAndHandleErrors.

if err != nil {
log.Fatalln(err)
}
Expand Down
4 changes: 1 addition & 3 deletions snippets/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"log"

firebase "firebase.google.com/go/v4"
"google.golang.org/api/option"
)

// ==================================================================
Expand All @@ -31,8 +30,7 @@ func cloudStorage() {
config := &firebase.Config{
StorageBucket: "<BUCKET_NAME>.appspot.com",
}
opt := option.WithCredentialsFile("path/to/serviceAccountKey.json")
app, err := firebase.NewApp(context.Background(), config, opt)
app, err := firebase.NewApp(context.Background(), config)
if err != nil {
log.Fatalln(err)
}
Expand Down
Loading