func (this *categoriesController) get(w http.ResponseWriter, req *http.Request) { categories := models.GetCategories() categoriesVM := []viewmodels.Category{} for _, category := range categories { categoriesVM = append(categoriesVM, converters.ConvertCategoryToViewModel(category)) } vm := viewmodels.GetCategories() vm.Categories = categoriesVM w.Header().Add("Content-Type", "text/html") responseWriter := util.GetResponseWriter(w, req) defer responseWriter.Close() this.template.Execute(responseWriter, vm) }
func (this *categoriesController) get(w http.ResponseWriter, req *http.Request) { _, er := req.Cookie("goSessionId") if er == nil { categories := models.GetCategories() categoriesVM := []viewmodels.Category{} for _, category := range categories { categoriesVM = append(categoriesVM, converter.ConvertCategoryToViewModel(category)) } vmc := viewmodels.GetCategory() vmc.Categories = categoriesVM vmc.LoggedIn = true w.Header().Add("Content-Type", "text/html") this.template.Execute(w, vmc) } else { http.Redirect(w, req, "/login", http.StatusFound) } }