diff options
Diffstat (limited to 'content/item.go')
-rw-r--r-- | content/item.go | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/content/item.go b/content/item.go index c847ed7..9eb3c16 100644 --- a/content/item.go +++ b/content/item.go @@ -1,6 +1,10 @@ package content -import "net/http" +import ( + "net/http" + + uuid "github.com/satori/go.uuid" +) // 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, @@ -10,12 +14,14 @@ type Sluggable interface { SetSlug(string) } -// Identifiable enables a struct to have its ID set. Typically this is done +// Identifiable enables a struct to have its ID set/get. 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 { + ItemID() int SetItemID(int) + UniqueID() uuid.UUID } // Hookable provides our user with an easy way to intercept or add functionality @@ -35,13 +41,13 @@ type Hookable interface { AfterReject(req *http.Request) error } - // Item should only be embedded into content type structs. type Item struct { - ID int `json:"id"` - Slug string `json:"slug"` - Timestamp int64 `json:"timestamp"` - Updated int64 `json:"updated"` + UUID uuid.UUID `json:"uuid"` + ID int `json:"id"` + Slug string `json:"slug"` + Timestamp int64 `json:"timestamp"` + Updated int64 `json:"updated"` } // Time partially implements the Sortable interface @@ -54,21 +60,29 @@ func (i Item) Touch() int64 { return i.Updated } -// ItemID partially implements the Sortable interface -func (i Item) ItemID() int { - return i.ID -} - // SetSlug sets the item's slug for its URL func (i *Item) SetSlug(slug string) { i.Slug = slug } +// ItemID gets the Item's ID field +// partially implements the Identifiable interface +func (i Item) ItemID() int { + return i.ID +} + // SetItemID sets the Item's ID field +// partially implements the Identifiable interface func (i *Item) SetItemID(id int) { i.ID = id } +// UniqueID gets the Item's UUID field +// partially implements the Identifiable interface +func (i Item) UniqueID() uuid.UUID { + return i.UUID +} + // BeforeSave is a no-op to ensure structs which embed Item implement Hookable func (i Item) BeforeSave(req *http.Request) error { return nil @@ -107,4 +121,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 -}
\ No newline at end of file +} |