-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(firestore): remove deprecated library firestore-gorilla-sessions #5312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(firestore): remove deprecated library firestore-gorilla-sessions #5312
Conversation
…a direct implementation of fs client
…samples into garciadiaz-fix-sessions-403118194
Here is the summary of changes. You are about to add 1 region tag.
You are about to delete 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @OremGLG, 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!
Summary of Changes
This pull request addresses the deprecation of the firestore-gorilla-sessions
library by implementing a direct Firestore session management approach. It includes a new sample demonstrating this implementation, effectively resolving issue b/403118194. The changes primarily involve removing the deprecated library and updating the session handling logic to interact directly with Firestore.
Highlights
- Dependency Removal: The
firestore-gorilla-sessions
dependency has been removed fromgo.mod
andgo.sum
, as it is deprecated. - Direct Firestore Implementation: The session management logic in
main.go
has been updated to directly use Firestore for session storage, eliminating the need for the deprecated library. - Cookie-Based Session Handling: The session identifier is now stored in a cookie named
session_id
, and the session data is retrieved and updated directly in Firestore based on this identifier. - Test Update: The test case has been updated to reflect the new session handling mechanism and includes a cleanup function to delete test documents.
Changelog
Click here to see the changelog
- getting-started/sessions/go.mod
- Removed
github.com/GoogleCloudPlatform/firestore-gorilla-sessions
andgithub.com/gorilla/sessions
dependencies. - Removed
github.com/gorilla/securecookie
indirect dependency.
- Removed
- getting-started/sessions/go.sum
- Removed entries related to
github.com/GoogleCloudPlatform/firestore-gorilla-sessions
and other unused dependencies. - Removed a large number of indirect dependencies that are no longer needed.
- Removed entries related to
- getting-started/sessions/main.go
- Updated copyright year from 2019 to 2025.
- Removed import of
firestoregorilla
andgorilla/sessions
. - Introduced
session
struct to store session data. - Modified
newApp
function to acceptprojectID
andcollectionID
and return anapp
struct directly. - Implemented cookie-based session handling in the
index
function. - Implemented direct Firestore interaction for session retrieval, creation, and update.
- getting-started/sessions/main_test.go
- Updated copyright year from 2019 to 2025.
- Updated
TestIndex
to align with the new session handling mechanism. - Added
cleanup
function to delete test documents after the test.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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.
The session's ID,
A cookie's gentle guide,
Firestore's embrace warm.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request removes the deprecated firestore-gorilla-sessions
library and implements a direct Firestore session management. The changes include updating dependencies in go.mod
and go.sum
, modifying the main application logic to handle sessions directly with Firestore, and updating the test file to reflect these changes. Overall, the changes seem well-structured and address the issue of using a deprecated library.
Summary of Findings
- Error Handling in
index
function: Theindex
function inmain.go
contains multiple error handling blocks that uselog.Printf
followed byhttp.Error
. It would be more efficient to create a helper function to handle these errors consistently. - Missing License Header Check in Test File: The test file
main_test.go
does not have a check for theGOLANG_SAMPLES_FIRESTORE_PROJECT
environment variable before proceeding with the tests. This could lead to unexpected behavior or failures if the environment variable is not set. - Collection Cleanup: The cleanup function in
main_test.go
iterates through all documents in the test collection and deletes them. This could be slow and inefficient for large collections. Consider using a more efficient method for cleaning up the test data.
Merge Readiness
The pull request is almost ready for merging. However, I recommend addressing the error handling consistency in the index
function and ensuring that the test environment is properly set up before merging. I am unable to directly approve this pull request, and other reviewers should review and approve this code before merging.
if err != nil { | ||
log.Printf("doc.Get error: %v", err) | ||
http.Error(w, "Error getting session", http.StatusInternalServerError) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider creating a helper function to handle Firestore errors consistently. This will reduce code duplication and improve maintainability.
handleFirestoreError(w, "doc.Get error", err)
// Helper function
func handleFirestoreError(w http.ResponseWriter, message string, err error) {
log.Printf("%s: %v", message, err)
http.Error(w, "Error getting session", http.StatusInternalServerError)
}
func TestIndex(t *testing.T) { | ||
|
||
projectID := os.Getenv("GOLANG_SAMPLES_FIRESTORE_PROJECT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for { | ||
doc, err := iter.Next() | ||
if err != nil { | ||
// Handle the case where the collection might not exist or other errors | ||
if err.Error() == "iterator ended" { | ||
log.Printf("Collection %s cleaned up or did not exist.", collectionID) | ||
return | ||
} | ||
log.Printf("Error iterating documents in %s: %v", collectionID, err) | ||
return | ||
} | ||
_, err = doc.Ref.Delete(ctx) | ||
if err != nil { | ||
log.Printf("Error deleting document %s in %s: %v", doc.Ref.ID, collectionID, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a timeout to the cleanup process to prevent indefinite hanging in case of issues with Firestore. Also, consider using DeleteAll
if available for more efficient cleanup.
// Add a timeout to the cleanup process
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
iter := client.Collection(collectionID).Documents(ctx)
for {
doc, err := iter.Next()
if err != nil {
// Handle the case where the collection might not exist or other errors
if err == iterator.Done {
log.Printf("Collection %s cleaned up or did not exist.", collectionID)
return
}
log.Printf("Error iterating documents in %s: %v", collectionID, err)
return
}
_, err = doc.Ref.Delete(ctx)
if err != nil {
log.Printf("Error deleting document %s in %s: %v", doc.Ref.ID, collectionID, err)
}
}
Description
Add new sample for sessions, this sample has a direct implementation of Firestore for to avoid using the deprecated package firestore-gorilla-sessions package.
Fixes b/403118194
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Follow up from PRs: #5237 and #5287
Checklist
go test -v ./..
(see Testing)gofmt
(see Formatting)go vet
(see Formatting)Please merge this PR once approved.