Example #1
0
// Save adds a single session to the response.
func (s *FilesystemStore) Save(r *http.Request, w http.ResponseWriter,
	session *Session) error {
	if session.ID == "" {
		k := securecookie.GenerateRandomKey(24)
		session.ID = fmt.Sprintf("%x", k)
	}
	if err := s.save(session); err != nil {
		return err
	}
	encoded, err := securecookie.EncodeMulti(session.Name(), session.ID,
		s.Codecs...)
	if err != nil {
		return err
	}
	options := s.Options
	if session.Options != nil {
		options = session.Options
	}
	cookie := &http.Cookie{
		Name:     session.Name(),
		Value:    encoded,
		Path:     options.Path,
		Domain:   options.Domain,
		MaxAge:   options.MaxAge,
		Secure:   options.Secure,
		HttpOnly: options.HttpOnly,
	}
	http.SetCookie(w, cookie)
	return nil
}
Example #2
0
// GetSession returns a session
func GetSession(r *http.Request, session_name string) (*sessions.Session, error) {
	s, err := M.Store.Get(r, session_name)
	if s.ID == "" {
		k := securecookie.GenerateRandomKey(24)
		s.ID = fmt.Sprintf("%x", k)
	}
	return s, err
}