qdb

package
v0.0.0-...-2a89af5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

func New

func New(n string) (Backend, error)

New is called to obtain a ready to use QuoteDB instance.

type BackendFactory

type BackendFactory func(hclog.Logger) (Backend, error)

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 KeysFunc

type KeysFunc func() ([]int, error)

KeysFunc is a type that the searcher can use to enumerate quote IDs.

type QLoaderFunc

type QLoaderFunc func(int) (Quote, error)

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

func FilterApproved(q []Quote) []Quote

FilterApproved is a helper that provides a list of quotes that have not been approved for public consumption.

func FilterUnapproved

func FilterUnapproved(q []Quote) []Quote

FilterUnapproved is a helper that provides a list of quotes that have been approved for public consumption.

func (*Quote) DisplayTime

func (q *Quote) DisplayTime() string

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 NewSearcher

func NewSearcher(l hclog.Logger) *Searcher

NewSearcher sets up a new searcher.

func (*Searcher) Index

func (s *Searcher) Index(q Quote)

Index indexes a quote.

func (*Searcher) LoadAll

func (s *Searcher) LoadAll()

LoadAll performs the initial load of all quotes and sets up the index.

func (*Searcher) Remove

func (s *Searcher) Remove(id int)

Remove removes a quote from the index.

func (*Searcher) Search

func (s *Searcher) Search(q string, size, from int) ([]Quote, int)

Search performs a paginated search and returns the results.

func (*Searcher) SetKeysFunc

func (s *Searcher) SetKeysFunc(kf KeysFunc)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL