feat(session): support v1
support v1
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
//
|
||||
// go install github.com/lib/pq
|
||||
//
|
||||
//
|
||||
// needs this table in your database:
|
||||
//
|
||||
// CREATE TABLE session (
|
||||
@@ -35,11 +34,12 @@
|
||||
// SessionSavePath = "user=a password=b dbname=c sslmode=disable"
|
||||
// SessionName = session
|
||||
//
|
||||
//
|
||||
// Usage:
|
||||
// import(
|
||||
// _ "github.com/beego/beego/session/postgresql"
|
||||
// "github.com/beego/beego/session"
|
||||
//
|
||||
// _ "github.com/beego/beego/session/postgresql"
|
||||
// "github.com/beego/beego/session"
|
||||
//
|
||||
// )
|
||||
//
|
||||
// func init() {
|
||||
@@ -113,15 +113,22 @@ func (st *SessionStore) SessionID() string {
|
||||
|
||||
// SessionRelease save postgresql session values to database.
|
||||
// must call this method to save values to database.
|
||||
func (st *SessionStore) SessionRelease(w http.ResponseWriter) {
|
||||
func (st *SessionStore) SessionRelease(_ http.ResponseWriter) {
|
||||
defer st.c.Close()
|
||||
b, err := session.EncodeGob(st.values)
|
||||
st.lock.RLock()
|
||||
values := st.values
|
||||
st.lock.RUnlock()
|
||||
b, err := session.EncodeGob(values)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
st.c.Exec("UPDATE session set session_data=$1, session_expiry=$2 where session_key=$3",
|
||||
b, time.Now().Format(time.RFC3339), st.sid)
|
||||
}
|
||||
|
||||
// SessionReleaseIfPresent save postgresql session values to database when key is present
|
||||
func (st *SessionStore) SessionReleaseIfPresent(w http.ResponseWriter) {
|
||||
st.SessionRelease(w)
|
||||
}
|
||||
|
||||
// Provider postgresql session provider
|
||||
|
||||
Reference in New Issue
Block a user