storages

Collection of key-value storages adapters for Golang

This project is maintained by reddec

Filesystem

API docs

Encoded

Constructors: New, NewDefault

Puts each data to separate file. File name generates from hash function (by default SHA256) applied to key. To prevent generates too much files in one directory, each filename is chopped to 4 slices by 4 characters.

URL initialization

Do not forget to import package!

file://<path>

Where:

Flat

Constructor: NewFlat

Key is equal to file name. Sub-directories (/ in key name) are not allowed.

Namespace are share key space with regular values.

URL initialization

Do not forget to import package!

file+flat://<path>

Where:

JSON

Constructor: NewJSONFile

Stores everything in one file. File overwrites atomically.

With JSON encoding all data presented as dictionary in data field and namespaces in namespaces field.

All information cached in-memory. Any modification operation will rewrite file fully.

This kind of storage is limited by RAM size and requires quite a number of sycalls for update. So it’s good for:

URL initialization

Do not forget to import package!

file+json://<path>

Where:

Usage

Flat

stor := filestorage.NewFlat("path/to/directory")
// Close() not required but implemented as NOP

Encoded

stor := filestorage.NewDefault("path/to/directory")
// Close() not required but implemented as NOP

Features

Namespaces

Support NamespacedStorage interface.

It allows make nested sub-storages with independent key space.

Example:

aliceStorage := storage.Namespace([]byte("alice"))
bobStorage := storage.Namespace([]byte("bob"))