Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoSuchQuote is returned in the event that a quote was // requested or configuration specified that returns no data. ErrNoSuchQuote = errors.New("no quote matches the given parameters") // ErrNoSuchBackend is returned when a QuoteDB backend is // requested that does not exist. ErrNoSuchBackend = errors.New("backend specified does not exist") // ErrInternal is returned for all uncategorized internal // database errors. ErrInternal = errors.New("an internal database error has occured") )
Functions ¶
func DoCallbacks ¶
func DoCallbacks()
DoCallbacks runs all the stored callbacks in an unspecified order
func Register ¶
func Register(name string, f BackendFactory)
Register registers a new BackendFactory to be later called when the database is initialized.
func RegisterCallback ¶
func RegisterCallback(cb Callback)
RegisterCallback adds a callback to allowed deferred startup tasks to run after package logging is configured.
func SetParentLogger ¶
func SetParentLogger(l hclog.Logger)
SetParentLogger sets the package level logger
Types ¶
type Backend ¶
type Backend interface { PutQuote(Quote) error DelQuote(Quote) error GetQuote(int) (Quote, error) // Search returns a set of quotes and how many are in the // total result set of this particular query. Search(string, int, int) ([]Quote, int) }
The Backend interface defines all the functions that a conformant QuoteDB will have. Implementations are of course allowed to provide additional helpers, but these are the only required methods.
type BackendFactory ¶
A BackendFactory creates a new QuoteDB Backend initialized and ready for use.
type Callback ¶
type Callback func()
A Callback is a function that will be run after package logging is configured.
type QLoaderFunc ¶
QLoaderFunc is a type that is passed in to allow loading quotes that are present in the search result set.
type Quote ¶
type Quote struct { ID int Quote string Rating int Approved bool ApprovedBy string ApprovedDate time.Time Edited bool EditedBy string EditedDate time.Time Submitted time.Time SubmittedIP string }
The Quote struct contains the various values that are stored with a quote.
func FilterApproved ¶
FilterApproved is a helper that provides a list of quotes that have not been approved for public consumption.
func FilterUnapproved ¶
FilterUnapproved is a helper that provides a list of quotes that have been approved for public consumption.
func (*Quote) DisplayTime ¶
DisplayTime is a convenience function to convert from the time stored in the database to a time format that is human readable.
type Searcher ¶
type Searcher struct {
// contains filtered or unexported fields
}
Searcher handles the maintenance of searching and returning results.
func (*Searcher) LoadAll ¶
func (s *Searcher) LoadAll()
LoadAll performs the initial load of all quotes and sets up the index.
func (*Searcher) SetKeysFunc ¶
SetKeysFunc sets up the keys function to allow the search index to bootstrap.
func (*Searcher) SetQLoader ¶
func (s *Searcher) SetQLoader(q QLoaderFunc)
SetQLoader sets the internal reference to the quote loader.