go-stash

command module
v0.0.0-...-00161ff Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2017 License: MIT Imports: 5 Imported by: 0

README

go-stash

Build Status codecov

Go-stash provides an in-memory data store, backed by a file on disk. It's designed for simple object storage when you don't need the overhead of a proper database.

Stash instances are safe for concurrent use by multiple goroutines. Data is serialized to disk using json.Marshal(), please see the JSON docs to understand how values are encoded to JSON.

Installation

$ go get -u github.com/dmjones500/go-stash/stash

Documentation

https://godoc.org/github.com/dmjones500/go-stash/stash

Quick Start

Create a new Stash, which auto-flushes to disk:

stash, err := stash.NewStash(filename, true)
if err != nil {
    // handle error
}

Save a complex structure:

err = stash.Save("accountData", account)

Retrieve it to another variable:

var anotherAccount Account
err = stash.Read("accountData", &anotherAccount)

If you don't enable auto-flush, then call Flush() when you want to persist all data to disk:

err = stash.Flush()

If a key doesn't exist, you'll get a NoSuchKeyError. The destination object will not be changed:

err = stash.Read("notExist", &foo) // returns a NoSuchKeyError, foo is unaltered

License

Go-stash is licensed under the MIT License.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package stash provides a basic in-memory data store backed by a file on disk.
Package stash provides a basic in-memory data store backed by a file on disk.

Jump to

Keyboard shortcuts

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