diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-11-16 02:47:57 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-11-16 02:47:57 -0800 |
commit | 79e770e1f8cf88ea85ffbd4e72d62dd82108dda0 (patch) | |
tree | dfaa45a28a6648ebf7be68732b90831eae0f7c24 | |
parent | 27f65ee344f094adeac73d33b524d6b805ab8910 (diff) |
rearranging code in item.go
-rw-r--r-- | content/item.go | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/content/item.go b/content/item.go index 14717bb..c847ed7 100644 --- a/content/item.go +++ b/content/item.go @@ -2,6 +2,40 @@ package content import "net/http" +// 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 +// and it will override the slug created by Item's SetSlug with your struct's +type Sluggable interface { + SetSlug(string) +} + +// Identifiable enables a struct to have its ID set. Typically this is done +// to set an ID to -1 indicating it is new for DB inserts, since by default +// a newly initialized struct would have an ID of 0, the int zero-value, and +// BoltDB's starting key per bucket is 0, thus overwriting the first record. +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 +} + + // Item should only be embedded into content type structs. type Item struct { ID int `json:"id"` @@ -73,37 +107,4 @@ func (i Item) BeforeReject(req *http.Request) error { // AfterReject is a no-op to ensure structs which embed Item implement Hookable func (i Item) AfterReject(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 -// and it will override the slug created by Item's SetSlug with your struct's -type Sluggable interface { - SetSlug(string) -} - -// Identifiable enables a struct to have its ID set. Typically this is done -// to set an ID to -1 indicating it is new for DB inserts, since by default -// a newly initialized struct would have an ID of 0, the int zero-value, and -// BoltDB's starting key per bucket is 0, thus overwriting the first record. -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 -} +}
\ No newline at end of file |