Created
March 11, 2016 11:46
-
-
Save JSila/3fe5f35ce802280d2376 to your computer and use it in GitHub Desktop.
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
// 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