From 186e54b0afe4d494247ffcac618ff43958b9247d Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Sun, 11 Aug 2019 00:57:08 +0200 Subject: [PATCH] try to remove gorilla context --- go.mod | 1 - xormstore.go | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index faee565..001a640 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/denisenkom/go-mssqldb v0.0.0-20190724012636-11b2859924c1 github.com/go-sql-driver/mysql v1.4.1 github.com/go-xorm/xorm v0.7.4 - github.com/gorilla/context v1.1.1 github.com/gorilla/securecookie v1.1.1 github.com/gorilla/sessions v0.0.0-20160922145804-ca9ada445741 github.com/lib/pq v1.0.0 diff --git a/xormstore.go b/xormstore.go index 85be252..2bdd316 100644 --- a/xormstore.go +++ b/xormstore.go @@ -37,6 +37,7 @@ For API to use in HTTP handlers see https://github.com/gorilla/sessions package xormstore import ( + "context" "encoding/base32" "net/http" "strings" @@ -45,7 +46,6 @@ import ( "github.com/lafriks/xormstore/util" "github.com/go-xorm/xorm" - "github.com/gorilla/context" "github.com/gorilla/securecookie" "github.com/gorilla/sessions" ) @@ -141,7 +141,9 @@ func (st *Store) New(r *http.Request, name string) (*sessions.Session, error) { return session, nil } - context.Set(r, contextKey(name), s) + //Add data to context + ctx := context.WithValue(r.Context(), contextKey(name), s) + r = r.WithContext(ctx) //Set context //TODO validate this or should be *r = *(r.WithContext(ctx)) } return session, nil @@ -149,7 +151,7 @@ func (st *Store) New(r *http.Request, name string) (*sessions.Session, error) { // Save session and set cookie header func (st *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error { - s, _ := context.Get(r, contextKey(session.Name())).(*xormSession) + s, _ := r.Context().Value(contextKey(session.Name())).(*xormSession) // delete if max age is < 0 if session.Options.MaxAge < 0 { @@ -188,7 +190,10 @@ func (st *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions. if _, err := st.e.Insert(s); err != nil { return err } - context.Set(r, contextKey(session.Name()), s) + //Add data to context + ctx := context.WithValue(r.Context(), contextKey(session.Name()), s) + r = r.WithContext(ctx) //Set context //TODO validate this or should be *r = *(r.WithContext(ctx)) + } else { s.Data = data s.UpdatedUnix = now