예제 #1
0
// load: load the session for the current connection.
func (s *session) load(w http.ResponseWriter, r *http.Request) {
	// get the stored session
	s.ss = storage.LoadSession(s.sid)

	// reset the session if requested
	matches := selectEndpointRegexp.FindStringSubmatch(r.URL.Path)
	if *debugLog {
		log.Printf("Session Load: URI %q matches: %v", r.URL.Path, matches)
	}
	if matches != nil {
		if len(matches[2]) > 0 {
			s.ss.SelectPuzzle(matches[2])
			log.Printf("Selected session %v puzzle %q at step %d.", s.sid, s.name(), s.step())
		}
		if matches[1] == "reset" {
			s.ss.RemoveAllSteps()
			log.Printf("Reset session %v puzzle %q to step %d", s.sid, s.name(), s.step())
		}
	}
}
예제 #2
0
// sessionSelect: find or create the session for the current connection.
func sessionSelect(w io.Writer, r *request) *session {
	id := getCookie(w, r)
	return &session{sid: id, ss: storage.LoadSession(id)}
}