alexedwards / scs

HTTP Session Management for Go
MIT License
2.05k stars 165 forks source link

Add a method to modify the deadline of the sessionData #149

Closed lwj5 closed 8 months ago

lwj5 commented 1 year ago

At the moment every session has a fixed lifetime which is set on the initialization of the session manager. There is no way to modify the deadline for an individual session after.

It would be useful if a method can be exposed to set the expiry for cases when the deadline differs from the default or modified due to other conditions.

func (s *SessionManager) Expire(ctx context.Context, expiry time.Time) {
    sd := s.getSessionDataFromContext(ctx)

    sd.mu.Lock()
    defer sd.mu.Unlock()
    sd.deadline = expiry
    sd.status = Modified
}

Let me know if I should proceed with a PR

alexedwards commented 1 year ago

@lwj5 Thanks, yes I'd be happy for a PR. I'm not sure that the method name Expire() is ideal --- perhaps SetDeadline() would be more explicit and complement with the existing Deadline() method?

lwj5 commented 1 year ago

Thanks for the reply. I'm maintaining a fork at https://github.com/Inquisico/go-session with this and an extended set of features we require. I'll add SetDeadline here when I have the time.

Feel free to do so if anyone else would like to go at it.

skast96 commented 1 year ago

Has this been added via a PR or is this still open? I need that feature as well.

alexedwards commented 9 months ago

There's no PR yet, as far as I know. I haven't had time to work on it, so a PR would still be very much appreciated.

petersanchez commented 8 months ago

This is great. I was looking into how to modify scs to support just this. I see the PR #181 is already submitted! Excellent.

alexedwards commented 8 months ago

PR merged. SetDeadline() is now available in v2.7.0. Thanks to all who helped on this :+1: