func articleHandler(w http.ResponseWriter, r *http.Request) { title := r.URL.Path[len("/article/"):] article, err := article.LoadArticleTitle(title) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } ArticleTemplate(w, r, article) }
func AddCommentHandler(w http.ResponseWriter, r *http.Request) { articleUrl := r.URL.Path[len("/submitcomment/"):] author := r.FormValue("name") date := time.Now().String() comment := r.FormValue("comment") // fix this loading art, err := article.LoadArticleTitle(articleUrl) if err != nil { http.NotFound(w, r) return } (&art).AddComment(author, date, comment) http.Redirect(w, r, "/article/"+articleUrl, http.StatusFound) }