quotes

package
v0.0.0-...-3f4038a Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is a quote database.

func Open

func Open(path string) (*DB, error)

Open opens the database file at path and returns a DB or an error.

func (*DB) Close

func (d *DB) Close() error

func (*DB) Create

func (d *DB) Create(q *Quote) error

Create takes a quote and saves it to the database, using the author name as the key. If the author already exists, Create returns an error.

func (*DB) Get

func (d *DB) Get(author string) (*Quote, error)

Get takes an author name and retrieves the corresponding quote from the DB.

func (*DB) List

func (d *DB) List() ([]*Quote, error)

List lists all records in the DB.

type Quote

type Quote struct {
	Author string `json:"author"`
	Text   string `json:"text"`
	Source string `json:"source,omitempty"`
}

Quote represents a quote, inlcuding its author and an optional source. The ID is a unique key.

func (*Quote) Deserialize

func (q *Quote) Deserialize(b []byte) error

Deserialize takes a byte slice that contains a gob-encoded quote and turns it back into a Quote.

func (Quote) Serialize

func (q Quote) Serialize() ([]byte, error)

Serialize returns a gob encoding of quote q.

func (*Quote) String

func (q *Quote) String() string

String implements the stringer interface. A Quote can now be used everywhere a string is expected.

Jump to

Keyboard shortcuts

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