data

package
v0.0.0-...-760c826 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyDatabase = errors.New("Database is empty")

ErrEmptyDatabase is returned when an empty database is used.

View Source
var ErrMissingFortune = errors.New("Could not find fortune with provided ID")

ErrMissingFortune is returned when a fortune for the provided ID is not found.

Functions

func ComputeID

func ComputeID(data string) string

ComputeID generates a SHA-based unique ID for a fortune.

Types

type Database

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

Database is an in-memory container for fortunes.

func NewDatabase

func NewDatabase(fortunes []string) *Database

NewDatabase creates a fortune.Database from an array of fortunes.

func Parse

func Parse(r io.Reader) (*Database, error)

Parse initializes a fortune.Database with the fortune data parsed from the provided io.Reader.

func (*Database) Count

func (d *Database) Count() int

Count returns the number of fortunes in the database.

func (*Database) Get

func (d *Database) Get(id string) (*Fortune, error)

Get returns a single fortune from the database.

func (*Database) List

func (d *Database) List() []*Fortune

List returns all fortunes in the database.

func (*Database) Random

func (d *Database) Random() (string, error)

Random returns the ID of a random fortune in the database.

type Fortune

type Fortune struct {
	ID   string `json:"id"`
	Data string `json:"data"`
}

Fortune is a data structure representing a fortune.

func NewFortune

func NewFortune(data string) Fortune

NewFortune instantiates a fortune.Fortune from the provided string.

Jump to

Keyboard shortcuts

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