Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func createPost(w http.ResponseWriter, r *http.Request) {
- var newPost Post
- json.NewDecoder(r.Body).Decode(&newPost)
- insForm, err := db.Prepare("INSERT INTO posts (user_id,title, body ) VALUES (? ,?, ?)")
- if err != nil {
- panic(err.Error())
- }
- insForm.Exec(newPost.UserID, newPost.Title, newPost.Body)
- }
- func createComment(w http.ResponseWriter, r *http.Request) {
- var newComment Comment
- json.NewDecoder(r.Body).Decode(&newComment)
- insForm, err := db.Prepare("INSERT INTO comments (post_id, body ) VALUES (? ,? )")
- if err != nil {
- panic(err.Error())
- }
- insForm.Exec(newComment.PostID, newComment.Body)
- }
Add Comment
Please, Sign In to add comment