// GetSessionUser returns username of current session user func GetSessionUser(r *http.Request, s *sessions.Sessions) (string, error) { //get current session sess, err := s.Get(r) if err != nil { return "", err } return sess.Username, nil }
// CheckTimeout Check timeout for concrete handler func CheckTimeout(r *http.Request, s *sessions.Sessions) error { // Check if current uri in map of timeouts timeout, ok := cfg.Timeouts[r.URL.Path] if !ok { return nil } sess, _ := s.Get(r) lastRequest, ok := sess.LastHandlers[r.RequestURI] if !ok { return nil } if time.Now().Unix()-lastRequest <= timeout { return fmt.Errorf(fmt.Sprint("One request '"+r.URL.Path+"' per ", timeout, " seconds limit.")) } return nil }