summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-11-08 16:48:12 -0800
committerSteve Manuel <nilslice@gmail.com>2016-11-08 16:48:12 -0800
commitdfa5e33f99f8727d36420981156c1ba8400b17b8 (patch)
tree7404d8d2eb804770c058ffbfffc9ade99ece3a23 /content
parente9e9ea47d8bcbdbcf91a2ad822e107d8561a9822 (diff)
adding before/after hooks to actions: save, delete, approve and reject
Diffstat (limited to 'content')
-rw-r--r--content/item.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/content/item.go b/content/item.go
index d099936..046ed04 100644
--- a/content/item.go
+++ b/content/item.go
@@ -1,5 +1,7 @@
package content
+import "net/http"
+
// Item should only be embedded into content type structs.
type Item struct {
ID int `json:"id"`
@@ -33,6 +35,26 @@ func (i *Item) SetItemID(id int) {
i.ID = id
}
+// BeforeSave is a no-op to ensure structs which embed Item implement Hookable
+func (i *Item) BeforeSave(req *http.Request) error {
+ return nil
+}
+
+// AfterSave is a no-op to ensure structs which embed Item implement Hookable
+func (i *Item) AfterSave(req *http.Request) error {
+ return nil
+}
+
+// BeforeDelete is a no-op to ensure structs which embed Item implement Hookable
+func (i *Item) BeforeDelete(req *http.Request) error {
+ return nil
+}
+
+// AfterDelete is a no-op to ensure structs which embed Item implement Hookable
+func (i *Item) AfterDelete(req *http.Request) error {
+ return nil
+}
+
// Sluggable makes a struct locatable by URL with it's own path
// As an Item implementing Sluggable, slugs may overlap. If this is an issue,
// make your content struct (or one which imbeds Item) implement Sluggable
@@ -48,3 +70,20 @@ type Sluggable interface {
type Identifiable interface {
SetItemID(int)
}
+
+// Hookable provides our user with an easy way to intercept or add functionality
+// to the different lifecycles/events a struct may encounter. Item implements
+// Hookable with no-ops so our user can override only whichever ones necessary.
+type Hookable interface {
+ BeforeSave(req *http.Request) error
+ AfterSave(req *http.Request) error
+
+ BeforeDelete(req *http.Request) error
+ AfterDelete(req *http.Request) error
+
+ BeforeApprove(req *http.Request) error
+ AfterApprove(req *http.Request) error
+
+ BeforeReject(req *http.Request) error
+ AfterReject(req *http.Request) error
+}