Skip to content

Instantly share code, notes, and snippets.

@s1s1ty
Created July 18, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1s1ty/ee8f5d03013e44f912f5d77b0d816d4d to your computer and use it in GitHub Desktop.
Save s1s1ty/ee8f5d03013e44f912f5d77b0d816d4d to your computer and use it in GitHub Desktop.
4th part
// 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