-
Notifications
You must be signed in to change notification settings - Fork 374
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
#80 add context_legacy.go and context.go for go 1.7 migration #95
Conversation
I suspect this is because the copied |
@elithrar thanks! I appreciate you taking the time to look. Let me know what I can do, if you don't have time to debug I will continue to try. Figured I'd just ping you since you probably have better insight on it than me. |
Still looking at this. Trying to debug where we forget to return any copy of the |
@elithrar after returning the request in the |
I think that was inevitable as we have to return any copied Request. Let me review tonight - thanks for working on this!
|
Apparently I already came to these conclusions a while ago: #80 I'd like to tag a release prior to merging this, and then a release after, so anyone who is vendoring can vendor pre- / post- breaking change. |
Thanks, let me know if there's anything else I can do to help |
Tagged v1.1 before I break this. Will do a v1.2 on the weekend when I merge this. |
@@ -76,8 +76,12 @@ type CookieStore struct { | |||
// | |||
// It returns a new session and an error if the session exists but could | |||
// not be decoded. | |||
func (s *CookieStore) Get(r *http.Request, name string) (*Session, error) { | |||
return GetRegistry(r).Get(s, name) | |||
func (s *CookieStore) Get(r *http.Request, name string) (*Session, *http.Request, error) { |
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.
We shouldn't need to return the store here, if we're already replacing the *http.Request
passed in.
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.
GetRegistry
API changes are OKStore
changes are not. I don't believe they are required.
@@ -179,8 +183,12 @@ func (s *FilesystemStore) MaxLength(l int) { | |||
// Get returns a session for the given name after adding it to the registry. | |||
// | |||
// See CookieStore.Get(). | |||
func (s *FilesystemStore) Get(r *http.Request, name string) (*Session, error) { | |||
return GetRegistry(r).Get(s, name) | |||
func (s *FilesystemStore) Get(r *http.Request, name string) (*Session, *http.Request, error) { |
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.
We shouldn't need to return the store here, if we're already replacing the *http.Request
passed in.
@@ -21,7 +21,7 @@ import ( | |||
// See CookieStore and FilesystemStore for examples. | |||
type Store interface { | |||
// Get should return a cached session. | |||
Get(r *http.Request, name string) (*Session, error) | |||
Get(r *http.Request, name string) (*Session, *http.Request, error) |
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.
Ditto. Breaking the Store
interface is a major break - it requires third-party stores to update, which may be out of the control of the package user.
Further: we should put a note in the README that indicates why this is breaking, and the steps to update your code. |
@elithrar the tests fail without the changes in the second commit, unless I'm misunderstanding something:
|
The internal changes are required, but you shouldn't need to change the method signature. You already have a request, so no need to return one. |
Sorry, I'm not sure what to do from here. The code didn't work until I made the Get methods return the request, so If I revert the signature of |
@elithrar example:
|
Btw, I also tried setting |
https://github.com/gorilla/sessions/tree/pr95 @shawnps diff --git a/sessions_test.go b/sessions_test.go
index f00813e..c166b05 100644
--- a/sessions_test.go
+++ b/sessions_test.go
@@ -48,7 +48,7 @@ func TestFlashes(t *testing.T) {
req, _ = http.NewRequest("GET", "http://localhost:8080/", nil)
rsp = NewRecorder()
// Get a session.
- if session, req, err = store.Get(req, "session-key"); err != nil {
+ if session, err = store.Get(req, "session-key"); err != nil {
t.Fatalf("Error getting session: %v", err)
}
// Get a flash.
@@ -71,7 +71,7 @@ func TestFlashes(t *testing.T) {
t.Fatal("No cookies. Header:", hdr)
}
- if _, req, err = store.Get(req, "session:key"); err.Error() != "sessions: invalid character in cookie name: session:key" {
+ if _, err = store.Get(req, "session:key"); err.Error() != "sessions: invalid character in cookie name: session:key" {
t.Fatalf("Expected error due to invalid cookie name")
}
@@ -81,7 +81,7 @@ func TestFlashes(t *testing.T) {
req.Header.Add("Cookie", cookies[0])
rsp = NewRecorder()
// Get a session.
- if session, req, err = store.Get(req, "session-key"); err != nil {
+ if session, err = store.Get(req, "session-key"); err != nil {
t.Fatalf("Error getting session: %v", err)
}
// Check all saved values.
@@ -114,7 +114,7 @@ func TestFlashes(t *testing.T) {
req, _ = http.NewRequest("GET", "http://localhost:8080/", nil)
rsp = NewRecorder()
// Get a session.
- if session, req, err = store.Get(req, "session-key"); err != nil {
+ if session, err = store.Get(req, "session-key"); err != nil {
t.Fatalf("Error getting session: %v", err)
}
// Get a flash.
@@ -141,7 +141,7 @@ func TestFlashes(t *testing.T) {
req.Header.Add("Cookie", cookies[0])
rsp = NewRecorder()
// Get a session.
- if session, req, err = store.Get(req, "session-key"); err != nil {
+ if session, err = store.Get(req, "session-key"); err != nil {
t.Fatalf("Error getting session: %v", err)
}
// Check all saved values.
diff --git a/store.go b/store.go
index f041a6b..0aab0d4 100644
--- a/store.go
+++ b/store.go
@@ -21,7 +21,7 @@ import (
// See CookieStore and FilesystemStore for examples.
type Store interface {
// Get should return a cached session.
- Get(r *http.Request, name string) (*Session, *http.Request, error)
+ Get(r *http.Request, name string) (*Session, error)
// New should create and return a new session.
//
@@ -76,12 +76,12 @@ type CookieStore struct {
//
// It returns a new session and an error if the session exists but could
// not be decoded.
-func (s *CookieStore) Get(r *http.Request, name string) (*Session, *http.Request, error) {
- var reg *Registry
- reg, r = GetRegistry(r)
+func (s *CookieStore) Get(r *http.Request, name string) (*Session, error) {
+ reg, req := GetRegistry(r)
ses, err := reg.Get(s, name)
+ *r = *req
- return ses, r, err
+ return ses, err
}
// New returns a session for the given name without adding it to the registry.
@@ -183,12 +183,12 @@ func (s *FilesystemStore) MaxLength(l int) {
// Get returns a session for the given name after adding it to the registry.
//
// See CookieStore.Get().
-func (s *FilesystemStore) Get(r *http.Request, name string) (*Session, *http.Request, error) {
- var reg *Registry
- reg, r = GetRegistry(r)
+func (s *FilesystemStore) Get(r *http.Request, name string) (*Session, error) {
+ reg, req := GetRegistry(r)
ses, err := reg.Get(s, name)
+ *r = *req
- return ses, r, err
+ return ses, err
}
// New returns a session for the given name without adding it to the registry. |
@elithrar got it, I'll push an update |
@elithrar does the new stuff look okay? Anything I can do? |
Thinking it through. I'd like to automate some PR creation for a few people
|
@elithrar ah you did mention the README. I'll add something to this PR updating the README, so please take a look when you have time! As for the PR creation for people this will break, I can investigate that as well if you'd like. I have a script that automatically makes PRs after running |
Might be able to use something like this to automate, or just use https://github.com/golang/tools/blob/master/refactor/rename/rename.go#L38 |
@elithrar I just added a note to the README, see the rendered Markdown here: https://github.com/shawnps/sessions/blob/dc17d8cc4b7165432d37bd224ae43309f97950a9/README.md#notes |
(comments/edit suggestions welcome of course) |
Following this long conversation, it appears changes are now ready to be pulled? |
We need to: a) tag the current HEAD before we break We also need to document it and reach out to those using the library
|
Just a friendly ping. Is there anything needs to be done to merge this in? |
@omeid I'd like to do more work to automatically create PRs on those who import us, don't vendor, and thus will have their applications break. gorilla/sessions pre-dates most vendoring tools and I suspect the intersection of those who use it and don't vendor is therefore very high. |
Take note of #105 - we may just fix it there. |
@@ -186,7 +184,9 @@ func init() { | |||
|
|||
// Save saves all sessions used during the current request. | |||
func Save(r *http.Request, w http.ResponseWriter) error { | |||
return GetRegistry(r).Save(w) | |||
var reg *Registry | |||
reg, r = GetRegistry(r) |
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.
If there was no registry saved in the request's context, we shouldn't create a new, empty one here, only to throw it away after telling it to save nothing. Instead, separate GetRegistry
into its two cases—one that returns an existing registry if it already exists, and one that wraps it and installs a fresh registry if there wasn't one before. This function should use the former and bail early if there was no existing registry.
This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days. |
Tests on Go 1.7 currently failing with:
Trying to debug. cc @elithrar