Documentation ¶
Overview ¶
Package item provides the default functionality to Ponzu's entities/data types, how they interact with the API, and how to override or enhance their abilities using various interfaces.
Index ¶
- func NormalizeString(s string) (string, error)
- func Slug(i Identifiable) (string, error)
- type CSVFormattable
- type Hookable
- type Identifiable
- type Item
- func (i *Item) AfterAPICreate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterAPIDelete(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterAPIResponse(res http.ResponseWriter, req *http.Request, data interface{}) error
- func (i *Item) AfterAPIUpdate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterAdminCreate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterAdminDelete(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterAdminUpdate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterDelete(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterDisable(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterEnable(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterReject(res http.ResponseWriter, req *http.Request) error
- func (i *Item) AfterSave(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeAPICreate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeAPIDelete(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeAPIResponse(res http.ResponseWriter, req *http.Request, data interface{}) (interface{}, error)
- func (i *Item) BeforeAPIUpdate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeAdminCreate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeAdminDelete(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeAdminUpdate(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeDelete(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeDisable(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeEnable(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeReject(res http.ResponseWriter, req *http.Request) error
- func (i *Item) BeforeSave(res http.ResponseWriter, req *http.Request) error
- func (i *Item) IndexContent() bool
- func (i *Item) ItemID() string
- func (i *Item) ItemSlug() string
- func (i *Item) ItemSpecifier() string
- func (i *Item) SetItemID(id string)
- func (i *Item) SetSlug(slug string)
- func (i *Item) SetSpecifier(specifier string)
- func (i *Item) SetUniqueID(uuid uuid.UUID)
- func (i *Item) String() string
- func (i *Item) Time() int64
- func (i *Item) Touch() int64
- func (i *Item) UniqueID() uuid.UUID
- type Pushable
- type Sluggable
- type Sortable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeString ¶
NormalizeString removes and replaces illegal characters for URLs and other path entities. Useful for taking user input and converting it for keys or URLs.
func Slug ¶
func Slug(i Identifiable) (string, error)
Slug returns a URL friendly string from the title of a post item
Types ¶
type CSVFormattable ¶
type CSVFormattable interface {
FormatCSV() []string
}
CSVFormattable is implemented with the method FormatCSV, which must return the ordered slice of JSON struct tag names for the type implementing it
type Hookable ¶
type Hookable interface { BeforeAPIResponse(http.ResponseWriter, *http.Request, interface{}) (interface{}, error) AfterAPIResponse(http.ResponseWriter, *http.Request, interface{}) error BeforeAPICreate(http.ResponseWriter, *http.Request) error AfterAPICreate(http.ResponseWriter, *http.Request) error BeforeAPIUpdate(http.ResponseWriter, *http.Request) error AfterAPIUpdate(http.ResponseWriter, *http.Request) error BeforeAPIDelete(http.ResponseWriter, *http.Request) error AfterAPIDelete(http.ResponseWriter, *http.Request) error BeforeAdminCreate(http.ResponseWriter, *http.Request) error AfterAdminCreate(http.ResponseWriter, *http.Request) error BeforeAdminUpdate(http.ResponseWriter, *http.Request) error AfterAdminUpdate(http.ResponseWriter, *http.Request) error BeforeAdminDelete(http.ResponseWriter, *http.Request) error AfterAdminDelete(http.ResponseWriter, *http.Request) error BeforeSave(http.ResponseWriter, *http.Request) error AfterSave(http.ResponseWriter, *http.Request) error BeforeDelete(http.ResponseWriter, *http.Request) error AfterDelete(http.ResponseWriter, *http.Request) error BeforeReject(http.ResponseWriter, *http.Request) error AfterReject(http.ResponseWriter, *http.Request) error BeforeEnable(http.ResponseWriter, *http.Request) error AfterEnable(http.ResponseWriter, *http.Request) error BeforeDisable(http.ResponseWriter, *http.Request) error AfterDisable(http.ResponseWriter, *http.Request) error }
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 Identifiable ¶
type Identifiable interface { ItemID() string SetItemID(string) UniqueID() uuid.UUID SetUniqueID(uuid.UUID) String() string ItemSpecifier() string SetSpecifier(string) }
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 Item ¶
type Item struct { UUID uuid.UUID `json:"uuid"` ID string `json:"id"` Slug string `json:"slug"` Timestamp int64 `json:"timestamp"` Updated int64 `json:"updated"` Specifier string `json:"specifier"` }
Item should only be embedded into entities type structs.
func (*Item) AfterAPICreate ¶
AfterAPICreate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterAPIDelete ¶
AfterAPIDelete is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterAPIResponse ¶
AfterAPIResponse is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterAPIUpdate ¶
AfterAPIUpdate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterAdminCreate ¶
AfterAdminCreate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterAdminDelete ¶
AfterAdminDelete is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterAdminUpdate ¶
AfterAdminUpdate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterDelete ¶
AfterDelete is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterDisable ¶
AfterDisable is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterEnable ¶
AfterEnable is a no-op to ensure structs which embed Item implement Hookable
func (*Item) AfterReject ¶
AfterReject is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAPICreate ¶
BeforeAPICreate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAPIDelete ¶
BeforeAPIDelete is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAPIResponse ¶
func (i *Item) BeforeAPIResponse(res http.ResponseWriter, req *http.Request, data interface{}) (interface{}, error)
BeforeAPIResponse is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAPIUpdate ¶
BeforeAPIUpdate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAdminCreate ¶
BeforeAdminCreate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAdminDelete ¶
BeforeAdminDelete is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeAdminUpdate ¶
BeforeAdminUpdate is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeDelete ¶
BeforeDelete is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeDisable ¶
BeforeDisable is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeEnable ¶
BeforeEnable is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeReject ¶
BeforeReject is a no-op to ensure structs which embed Item implement Hookable
func (*Item) BeforeSave ¶
BeforeSave is a no-op to ensure structs which embed Item implement Hookable
func (*Item) IndexContent ¶
IndexContent determines if a type should be indexed for searching partially implements search.Searchable
func (*Item) ItemID ¶
ItemID gets the Item's ID field partially implements the Identifiable interface
func (*Item) ItemSpecifier ¶
ItemSpecifier gets the Item's specifier field partially implements the Identifiable interface
func (*Item) SetItemID ¶
SetItemID sets the Item's ID field partially implements the Identifiable interface
func (*Item) SetSpecifier ¶
SetSpecifier sets the Item's specifier field partially implements the Identifiable interface
func (*Item) SetUniqueID ¶
SetUniqueID sets the Item's UUID field partially implements the Identifiable interface
type Pushable ¶
type Pushable interface { // the values contained by fields returned by Push must strictly be URL paths Push(http.ResponseWriter, *http.Request) ([]string, error) }
Pushable lets a user define which values of certain struct fields are 'pushed' down to a client via HTTP/2 Server Push. All items in the slice should be the json tag names of the struct fields to which they correspond.