gin-session icon indicating copy to clipboard operation
gin-session copied to clipboard

Updated package to support go-session/session/v3

Open yehuizhang opened this issue 2 years ago • 1 comments

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

yehuizhang avatar Jan 09 '23 11:01 yehuizhang

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)
}

coding-or-afk avatar Aug 10 '23 14:08 coding-or-afk