chore(snippets): updated code samples to use ADC and supported APIs#752
chore(snippets): updated code samples to use ADC and supported APIs#752lahirumaramba wants to merge 1 commit intodevfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors several code samples to align with best practices and updated API standards. It transitions Firebase app initialization from explicit service account keys to Application Default Credentials, simplifying authentication. Additionally, it modernizes Firebase Messaging usage by replacing deprecated batch and multicast send functions with their currently supported counterparts, ensuring the samples remain functional and demonstrate recommended API usage. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates code samples to use Application Default Credentials (ADC) and modern Firebase APIs, which is a great improvement. The changes to use ADC in db.go and storage.go are correct. The updates in messaging.go to replace deprecated SendAll and SendMulticast APIs are also correct.
My review includes a few suggestions for snippets/messaging.go to improve context handling and address code duplication that arose from these changes. Specifically, several functions are not propagating the context they receive, and some functions have become duplicates of others.
| } | ||
|
|
||
| br, err := client.SendAll(context.Background(), messages) | ||
| br, err := client.SendEach(context.Background(), messages) |
There was a problem hiding this comment.
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.
| br, err := client.SendEach(context.Background(), messages) | |
| br, err := client.SendEach(ctx, messages) |
| } | ||
|
|
||
| br, err := client.SendAll(context.Background(), messages) | ||
| br, err := client.SendEach(context.Background(), messages) |
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| br, err := client.SendMulticast(context.Background(), message) | ||
| br, err := client.SendEachForMulticast(context.Background(), message) |
There was a problem hiding this comment.
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.
| br, err := client.SendEachForMulticast(context.Background(), message) | |
| br, err := client.SendEachForMulticast(ctx, message) |
| } | ||
|
|
||
| br, err := client.SendMulticast(context.Background(), message) | ||
| br, err := client.SendEachForMulticast(context.Background(), message) |
There was a problem hiding this comment.
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.
| br, err := client.SendEachForMulticast(context.Background(), message) | |
| br, err := client.SendEachForMulticast(ctx, message) |
| } | ||
|
|
||
| br, err := client.SendMulticast(context.Background(), message) | ||
| br, err := client.SendEachForMulticast(context.Background(), message) |
There was a problem hiding this comment.
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.
| // [END send_to_condition_golang] | ||
| } | ||
|
|
||
| func sendAll(ctx context.Context, client *messaging.Client) { |
There was a problem hiding this comment.
I think we can remove these 3 snippets completely since there are no longer referenced in devsite and we already have the migrated version of the snippets.
https://firebase.google.com/docs/cloud-messaging/send/admin-sdk#go_1
Updated code samples in the snippets directory to use Application Default Credentials (ADC) wherever appropriate instead of requiring explicit service account keys. Also replaced the deprecated messaging APIs
SendAllandSendMulticastwith their modern, supported equivalentsSendEachandSendEachForMulticast.