blob: 81593b6b30bf1c76edc0f08145d5545984e2f31f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package content
// 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"`
}
// Time partially implements the Sortable interface
func (i Item) Time() int64 {
return i.Timestamp
}
// Touch partially implements the Sortable interface
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
}
// SetContentID sets the Item's ID field
func (i *Item) SetContentID(id int) {
i.ID = id
}
// 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 {
SetContentID(int)
}
|