diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-12-06 02:16:29 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-12-06 02:16:29 -0800 |
commit | 40b5cfe2289b179c511a6c73757bb64228f0bc82 (patch) | |
tree | 47d28cef40b495cf3e52c65b27aa69ffe605a171 /content | |
parent | d28d2b6a44bea1f269feadc2b773253a95649f52 (diff) |
cleanup template, move ContentName into base Item as String on Identifiable interface, also makes Item implement Stringer, useful in fmt funcs
Diffstat (limited to 'content')
-rw-r--r-- | content/item.go | 8 | ||||
-rw-r--r-- | content/types.go | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/content/item.go b/content/item.go index 9eb3c16..e6c8243 100644 --- a/content/item.go +++ b/content/item.go @@ -1,6 +1,7 @@ package content import ( + "fmt" "net/http" uuid "github.com/satori/go.uuid" @@ -22,6 +23,7 @@ type Identifiable interface { ItemID() int SetItemID(int) UniqueID() uuid.UUID + String() string } // Hookable provides our user with an easy way to intercept or add functionality @@ -83,6 +85,12 @@ func (i Item) UniqueID() uuid.UUID { return i.UUID } +// String formats an Item into a printable value +// partially implements the Identifiable interface +func (i Item) String() string { + return fmt.Sprintf("Item ID: %s", i.UniqueID()) +} + // BeforeSave is a no-op to ensure structs which embed Item implement Hookable func (i Item) BeforeSave(req *http.Request) error { return nil diff --git a/content/types.go b/content/types.go index ede2b58..696d589 100644 --- a/content/types.go +++ b/content/types.go @@ -6,13 +6,13 @@ const ( There is no type registered for %[1]s Add this to the file which defines %[1]s{} in the 'content' package: ---------------------------------------------------------------------------+ -func init() { - Types["%[1]s"] = func() interface{} { return new(%[1]s) } -} + + func init() { + Types["%[1]s"] = func() interface{} { return new(%[1]s) } + } ---------------------------------------------------------------------------+ + ` ) |