diff --git a/comments/comments.go b/comments/comments.go index 8f3fecf..04451e1 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -75,7 +75,7 @@ func (cs *Service) ServeComments(post string, w http.ResponseWriter, r *http.Req if r.Method == "POST" { return cs.Comment(post, Comment{ Name: user, - Text: r.FormValue("Text"), + Text: readCommentText(r), IP: r.RemoteAddr, Date: time.Now(), }) @@ -90,6 +90,12 @@ func (cs *Service) ServeComments(post string, w http.ResponseWriter, r *http.Req return nil } +func readCommentText(r *http.Request) string { + comment := struct{ Text string }{} + json.NewDecoder(r.Body).Decode(&comment) + return comment.Text +} + func (cs *Service) Comment(post string, c Comment) error { return cs.Storage.Store(post, c) } @@ -101,7 +107,28 @@ func (cs *Service) Load(post string) ([]Comment, error) { func (cs *Service) WriteHTML(post string, w io.Writer) (int64, error) { buf := &bytes.Buffer{} tmpl := template.Must(template.New("").Parse( - `
- {{range $idx, $elem := .}}+