// Template renders HTML templates func Template(c web.C, w http.ResponseWriter, r *http.Request, templates []string, name string, data map[string]interface{}) error { funcMap := template.FuncMap{ "formatTime": formatTime, } t, err := template.New("").Delims("{{{", "}}}").Funcs(funcMap).ParseFiles(templates...) if err != nil { return err } var loggedIn bool user, err := helpers.CurrentUser(c) if err != nil { loggedIn = false } else { loggedIn = true } data["CurrentUser"] = user data["UserSignedIn"] = loggedIn session := helpers.CurrentSession(c) data["Flashes"] = session.Flashes() session.Save(r, w) err = t.ExecuteTemplate(w, name, data) if err != nil { return err } return nil }
func ResultsIndex(c web.C, w http.ResponseWriter, req *http.Request) { user, err := helpers.CurrentUser(c) if err != nil { renderError(c, w, req, "You need to re-authenticate", http.StatusUnauthorized) return } checkId, err := strconv.ParseInt(c.URLParams["check_id"], 10, 64) if err != nil { renderError(c, w, req, "Check not found", http.StatusNotFound) return } check, err := user.Check(checkId) if err != nil { renderError(c, w, req, "Check not found", http.StatusNotFound) return } results, err := check.Results() if err != nil { renderError(c, w, req, "No results found", http.StatusNotFound) return } render.JSON(w, http.StatusOK, results) }