gin-session
gin-session copied to clipboard
Updated package to support go-session/session/v3
Problem:
I am developing a new program using both go-session/session/v3 and go-session/gin-session and I noticed that when I call ginsession.New(session.SetSecure(false)), my IDE pops an error stating that go-session/session/v3.Option is not compatible with go-session/session.Option
Proposed solution
- Upgrade package to use go module
- Upgrade package to use
go-session/session/v3 - Upgrade package to use new version of Go
func Destroy(ctx *gin.Context) error {
v, ok := ctx.Get(manageKey)
if !ok {
return fmt.Errorf("invalid session manager")
}
return v.(*session.Manager).Destroy(nil, ctx.Writer, ctx.Request)
}
// Refresh a session and return to session storage
func Refresh(ctx *gin.Context) (session.Store, error) {
v, ok := ctx.Get(manageKey)
if !ok {
return nil, fmt.Errorf("invalid session manager")
}
return v.(*session.Manager).Refresh(nil, ctx.Writer, ctx.Request)
}
would be changed to ?
// Destroy a session
func Destroy(ctx *gin.Context) error {
v, ok := ctx.Get(manageKey)
if !ok {
return fmt.Errorf("invalid session manager")
}
return v.(*session.Manager).Destroy(context.TODO(), ctx.Writer, ctx.Request)
}
// Refresh a session and return to session storage
func Refresh(ctx *gin.Context) (session.Store, error) {
v, ok := ctx.Get(manageKey)
if !ok {
return nil, fmt.Errorf("invalid session manager")
}
return v.(*session.Manager).Refresh(context.TODO(), ctx.Writer, ctx.Request)
}