-
Notifications
You must be signed in to change notification settings - Fork 17
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
Session: multisession and metadata #5
Conversation
This CR nests multiple logins under one key. This is a nice property for operators because it keeps an individual's login session in one place instead of having to build a lookup index elsewhere mapping user->active sessions. It uses lazy deletion and expiration checks. There's a global expiration which exists for memcache or redis auto-expiration. There exists an inherent race if multiple sessions are being set at once. This race results in the last Set succeeding. In practice, an individual user shouldn't realistically be logging into two or more devices at the same time.
This CR adds a field to the session which enables storing additional optional metadata with the message. It's a byteslice so any data must be pre-serialized before getting stored into the backend. It can be retrieved through the ActiveSession method.
@@ -25,7 +25,7 @@ type server struct { | |||
var email = []byte("super@exa::mple.com") | |||
|
|||
func (s *server) login(w http.ResponseWriter, r *http.Request) { | |||
err := s.j.Set(r.Context(), w, email) | |||
err := s.j.Set(r.Context(), w, email, []byte(r.UserAgent())) |
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.
🙌
@@ -26,6 +26,7 @@ details. | |||
- CSRF Protection | |||
- Context aware | |||
- Fast | |||
- Multiple sessions under one key |
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.
expand on this.
@@ -27,6 +27,9 @@ func (s *Store) Store(ctx context.Context, key, value []byte, exp time.Time) err | |||
|
|||
func (s *Store) Fetch(ctx context.Context, key []byte) ([]byte, error) { | |||
i, err := s.mc.Get(string(key)) | |||
if err == memcache.ErrCacheMiss { |
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.
Satisfies the documented Fetch
in the Storage
interface.
No description provided.