// implement session.Store.Get() func (s *store) Get(sid string) (*session.Session, error) { s.Lock() defer s.Unlock() filepath := s.saveDir + sid data := make(map[interface{}]interface{}) f, err := os.Open(filepath) defer f.Close() if err != nil { if os.IsNotExist(err) { return session.NewSession(sid, data, s), nil } return nil, err } b, err := ioutil.ReadAll(f) if err != nil { return nil, err } de := gob.NewDecoder(bytes.NewBuffer(b)) err = de.Decode(&data) if err != nil { return nil, err } return session.NewSession(sid, data, s), nil }
// implement session.Store.Get() func (s *store) Get(sid string) (*session.Session, error) { s.Lock() defer s.Unlock() ret, found := s.sessions[sid] if found { return ret, nil } /* 声明新的session实例 */ ret = session.NewSession(sid, make(map[interface{}]interface{}), s) s.sessions[sid] = ret return ret, nil }