func newSessionStoreWithUserId(sessionId string, userId int64) sessions.Store { result := ramstore.NewRAMStore(900) sessionData := make(map[interface{}]interface{}) s := session_util.UserIdSession{&sessions.Session{Values: sessionData}} s.SetUserId(userId) result.Data.Save(sessionId, sessionData) return result }
func TestUserSessionNewSession(t *testing.T) { userStore := errorStore{} sessionStore := ramstore.NewRAMStore(900) r := &http.Request{} us, err := session_util.NewUserSession( sessionStore, r, kSessionCookieName, func(s *sessions.Session) session_util.UserSession { return newUserSession(s) }, userStore, errNoSuchId) if err != nil { t.Fatalf("An error happened getting userSession: %v", err) } defer context.Clear(r) myUserSession := us.(*userSession) if output := myUserSession.User; output != nil { t.Error("Should not have user instance in user session.") } }
var ( fSSLCrt string fSSLKey string fPort string fDb string fIcon string ) var ( errNotLoggedIn = errors.New("vsafe app: not logged in.") ) var ( kDoer db.Doer kStore for_sqlite.Store kSessionStore = ramstore.NewRAMStore(kSessionTimeout) kPollingStore = asPollingStore(kSessionStore) ) func main() { flag.Parse() if fDb == "" { fmt.Println("Need to specify at least -db flag.") flag.Usage() return } setupDb(fDb) mux := http.NewServeMux() http.HandleFunc("/", rootRedirect) http.Handle("/static/", http.StripPrefix("/static", static.New())) if fIcon != "" {
func init() { loginSessionName = "loginInfo" //登录session名称 session = ramstore.NewRAMStore(3600) //创建session }