storage

package
v0.0.0-...-8c7dfbf Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adage

type Adage struct {
	ID        uuid.UUID
	Body      string
	Tags      []string
	Author    string
	Source    string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Adage is an entry in the database

func DeserializeAdage

func DeserializeAdage(data []byte) (*Adage, error)

DeserializeAdage converts a byte array into an Adage struct

func GetAdage

func GetAdage(db *bolt.DB) (*Adage, error)

GetAdage gets a random adage from the database

func GetAdageFromAll

func GetAdageFromAll(db *bolt.DB, excludes []string) (*Adage, error)

GetAdageFromAll gets an Adage from anywhere in the database

func GetAdageFromCategories

func GetAdageFromCategories(db *bolt.DB, tags []string, excludes []string, exclusive bool) (*Adage, error)

func (*Adage) Insert

func (adage *Adage) Insert(db *bolt.DB) error

Insert the adage to the database

func (*Adage) Serialize

func (adage *Adage) Serialize() ([]byte, error)

Serialize converts the structure to a byte array for saving into the database. We're just going to serialize it to JSON for now. I messed around with the gob package and it's actually slower to initialize all the object and buffers for each serialization and trying to reuse components can lead to corrupt binaries. The other alternative is something like Protobufs but I'm not sure if it's worth the added complexity. Right now we should be trying to make sure we almost never serialize/deserialize underlying data and instead do everything through indexes.

Jump to

Keyboard shortcuts

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