Skip to content

Instantly share code, notes, and snippets.

@JSila
Created March 11, 2016 11:46
Show Gist options
  • Save JSila/3fe5f35ce802280d2376 to your computer and use it in GitHub Desktop.
Save JSila/3fe5f35ce802280d2376 to your computer and use it in GitHub Desktop.
// I created Delete method on Post struct
func (p *Post) Delete(db *DB) error {
_, err := db.Exec("DELETE FROM posts WHERE id = ?", p.ID)
if err != nil {
return err
}
return nil
}
// I added method DeletePost to Datastore interface
type Datastore interface {
...
DeletePost(post *Post) error
}
// Implementation of DeletePost
func (db *DB) DeletePost(post *Post) error {
return post.Delete(db)
}
// I created Destroy method on Env receiver (I'm using gin-gonic)
func (e *Env) Destroy(c *gin.Context) {
post, err := ctrl.DB.GetPost(c.Param("id"))
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment