jrsanborn

Untitled

May 10th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.62 KB | None | 0 0
  1. func createPost(w http.ResponseWriter, r *http.Request) {
  2.     var newPost Post
  3.     json.NewDecoder(r.Body).Decode(&newPost)
  4.     insForm, err := db.Prepare("INSERT INTO posts (user_id,title, body ) VALUES (? ,?, ?)")
  5.     if err != nil {
  6.         panic(err.Error())
  7.     }
  8.     insForm.Exec(newPost.UserID, newPost.Title, newPost.Body)
  9. }
  10.  
  11. func createComment(w http.ResponseWriter, r *http.Request) {
  12.     var newComment Comment
  13.     json.NewDecoder(r.Body).Decode(&newComment)
  14.     insForm, err := db.Prepare("INSERT INTO comments (post_id, body ) VALUES (? ,? )")
  15.     if err != nil {
  16.         panic(err.Error())
  17.     }
  18.    
  19.     insForm.Exec(newComment.PostID, newComment.Body)
  20. }
Add Comment
Please, Sign In to add comment