1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-15 04:41:01 +00:00
1. session move from astaxie/session to beego/session
2. support 4 type session
This commit is contained in:
astaxie
2013-04-05 23:50:53 +08:00
parent 69f40ad18a
commit 2573696860
9 changed files with 645 additions and 31 deletions

View File

@ -2,8 +2,7 @@ package beego
import (
"fmt"
"github.com/astaxie/session"
_ "github.com/astaxie/session/providers/memory"
"github.com/astaxie/beego/session"
"html/template"
"net"
"net/http"
@ -31,9 +30,10 @@ var (
AppConfig *Config
//related to session
SessionOn bool // wheather auto start session,default is false
SessionProvider string // default session provider memory
SessionProvider string // default session provider memory mysql redis
SessionName string // sessionName cookie's name
SessionGCMaxLifetime int64 // session's gc maxlifetime
SessionSavePath string // session savepath if use mysql/redis/file this set to the connectinfo
UseFcgi bool
GlobalSessions *session.Manager //GlobalSessions
@ -60,6 +60,7 @@ func init() {
SessionProvider = "memory"
SessionName = "beegosessionID"
SessionGCMaxLifetime = 3600
SessionSavePath = ""
UseFcgi = false
} else {
HttpAddr = AppConfig.String("httpaddr")
@ -109,6 +110,11 @@ func init() {
} else {
SessionName = ar
}
if ar := AppConfig.String("sessionsavepath"); ar == "" {
SessionSavePath = ""
} else {
SessionSavePath = ar
}
if ar, err := AppConfig.Int("sessiongcmaxlifetime"); err != nil && ar != 0 {
int64val, _ := strconv.ParseInt(strconv.Itoa(ar), 10, 64)
SessionGCMaxLifetime = int64val
@ -222,7 +228,7 @@ func Run() {
BeeApp.Router(`/debug/pprof/:pp([\w]+)`, &ProfController{})
}
if SessionOn {
GlobalSessions, _ = session.NewManager(SessionProvider, SessionName, SessionGCMaxLifetime)
GlobalSessions, _ = session.NewManager(SessionProvider, SessionName, SessionGCMaxLifetime, SessionSavePath)
go GlobalSessions.GC()
}
err := BuildTemplate(ViewsPath)