Skip to content

Instantly share code, notes, and snippets.

@s1s1ty s1s1ty/go-sql-4.go

Created Jul 18, 2018
What would you like to do?
4th part
// CreatePost create a new post
func CreatePost(w http.ResponseWriter, r *http.Request) {
var post Post
query, err := db.Prepare("Insert posts SET title=?, content=?")
_, er := query.Exec(post.Title, post.Content)
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
You can’t perform that action at this time.