alexedwards / scs

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

Expose CtxStore interface to allow custom implementation #166

Closed gmhafiz closed 9 months ago

gmhafiz commented 1 year ago

Right now only Store interface is exposed but not CtxStore. This means custom implementation on context-based methods are not possible

package scs

type SessionManager struct {
    // Store controls the session store where the session data is persisted.
    Store Store

    // CtxStore is context-based that controls the session store where the session data is persisted.
    CtxStore CtxStore
package mypackage

manager := scs.New()
manager.CtxStore = mycustomstore.New(db) // not possible because CtxStore is not exported

PR: https://github.com/alexedwards/scs/pull/165

alexedwards commented 9 months ago

If you have a custom store implementation that satisfies CtxStore, you can set it to SessionManager.Store and it will call the FindCtx, CommitCtx and DeleteCtx methods as necessary. There's no need to introduce another field to the SessionManager struct.