Created
July 18, 2018 17:07
-
-
Save s1s1ty/ee8f5d03013e44f912f5d77b0d816d4d to your computer and use it in GitHub Desktop.
4th part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CreatePost create a new post | |
func CreatePost(w http.ResponseWriter, r *http.Request) { | |
var post Post | |
json.NewDecoder(r.Body).Decode(&post) | |
query, err := db.Prepare("Insert posts SET title=?, content=?") | |
catch(err) | |
_, er := query.Exec(post.Title, post.Content) | |
catch(er) | |
defer query.Close() | |
respondwithJSON(w, http.StatusCreated, map[string]string{"message": "successfully created"}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment