Documentation
¶
Overview ¶
Package gokv contains a simple key-value store abstraction in the form of a Go interface. Implementations of the gokv.Store interface can be found in the sub-packages.
Usage ¶
Example code for using Redis:
package main
import (
"fmt"
"github.com/philippgille/gokv"
"github.com/philippgille/gokv/redis"
)
type foo struct {
Bar string
}
func main() {
options := redis.DefaultOptions // Address: "localhost:6379", Password: "", DB: 0
// Create client
client, err := redis.NewClient(options)
if err != nil {
panic(err)
}
defer client.Close()
// Store, retrieve, print and delete a value
interactWithStore(client)
}
// interactWithStore stores, retrieves, prints and deletes a value.
// It's completely independent of the store implementation.
func interactWithStore(store gokv.Store) {
// Store value
val := foo{
Bar: "baz",
}
err := store.Set("foo123", val)
if err != nil {
panic(err)
}
// Retrieve value
retrievedVal := new(foo)
found, err := store.Get("foo123", retrievedVal)
if err != nil {
panic(err)
}
if !found {
panic("Value not found")
}
fmt.Printf("foo: %+v", *retrievedVal) // Prints `foo: {Bar:baz}`
// Delete value
err = store.Delete("foo123")
if err != nil {
panic(err)
}
}
More details can be found on https://github.com/philippgille/gokv.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store interface {
// Set stores the given value for the given key.
// The implementation automatically marshalls the value.
// The marshalling format depends on the implementation. It can be JSON, gob etc.
// The key must not be "" and the value must not be nil.
Set(k string, v interface{}) error
// Get retrieves the value for the given key.
// The implementation automatically unmarshalls the value.
// The unmarshalling source depends on the implementation. It can be JSON, gob etc.
// The automatic unmarshalling requires a pointer to an object of the correct type
// being passed as parameter.
// In case of a struct the Get method will populate the fields of the object
// that the passed pointer points to with the values of the retrieved object's values.
// If no value is found it returns (false, nil).
// The key must not be "" and the pointer must not be nil.
Get(k string, v interface{}) (found bool, err error)
// Delete deletes the stored value for the given key.
// Deleting a non-existing key-value pair does NOT lead to an error.
// The key must not be "".
Delete(k string) error
// Close must be called when the work with the key-value store is done.
// Most (if not all) implementations are meant to be used long-lived,
// so only call Close() at the very end.
// Depending on the store implementation it might do one or more of the following:
// Make sure all pending updates make their way to disk,
// finish open transactions,
// close the file handle to an embedded DB,
// close the connection to the DB server,
// release any open resources,
// etc.
// Some implementation might not need the store to be closed,
// but as long as you work with the gokv.Store interface you never know which implementation
// is passed to your method, so you should always call it.
Close() error
}
Store is an abstraction for different key-value store implementations. A store must be able to store, retrieve and delete key-value pairs, with the key being a string and the value being any Go interface{}.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package badgerdb contains an implementation of the `gokv.Store` interface for BadgerDB.
|
Package badgerdb contains an implementation of the `gokv.Store` interface for BadgerDB. |
|
Package bbolt contains an implementation of the `gokv.Store` interface for bbolt (formerly known as Bolt / Bolt DB).
|
Package bbolt contains an implementation of the `gokv.Store` interface for bbolt (formerly known as Bolt / Bolt DB). |
|
Package bigcache contains an implementation of the `gokv.Store` interface for BigCache.
|
Package bigcache contains an implementation of the `gokv.Store` interface for BigCache. |
|
Package cockroachdb contains an implementation of the `gokv.Store` interface for CockroachDB.
|
Package cockroachdb contains an implementation of the `gokv.Store` interface for CockroachDB. |
|
Package consul contains an implementation of the `gokv.Store` interface for Consul.
|
Package consul contains an implementation of the `gokv.Store` interface for Consul. |
|
Package datastore contains an implementation of the `gokv.Store` interface for Google Cloud Datastore.
|
Package datastore contains an implementation of the `gokv.Store` interface for Google Cloud Datastore. |
|
Package dynamodb contains an implementation of the `gokv.Store` interface for Amazon DynamoDB.
|
Package dynamodb contains an implementation of the `gokv.Store` interface for Amazon DynamoDB. |
|
Package encoding is a wrapper for the core functionality of packages like "encoding/json" and "encoding/gob".
|
Package encoding is a wrapper for the core functionality of packages like "encoding/json" and "encoding/gob". |
|
Package etcd contains an implementation of the `gokv.Store` interface for etcd.
|
Package etcd contains an implementation of the `gokv.Store` interface for etcd. |
|
Package file contains an implementation of the `gokv.Store` interface for local files.
|
Package file contains an implementation of the `gokv.Store` interface for local files. |
|
Package freecache contains an implementation of the `gokv.Store` interface for FreeCache.
|
Package freecache contains an implementation of the `gokv.Store` interface for FreeCache. |
|
Package gomap contains an implementation of the `gokv.Store` interface for a Go map.
|
Package gomap contains an implementation of the `gokv.Store` interface for a Go map. |
|
Package ignite contains an implementation of the `gokv.Store` interface for Apache Ignite.
|
Package ignite contains an implementation of the `gokv.Store` interface for Apache Ignite. |
|
Package leveldb contains an implementation of the `gokv.Store` interface for LevelDB.
|
Package leveldb contains an implementation of the `gokv.Store` interface for LevelDB. |
|
Package memcached contains an implementation of the `gokv.Store` interface for Memcached.
|
Package memcached contains an implementation of the `gokv.Store` interface for Memcached. |
|
Package mongodb contains an implementation of the `gokv.Store` interface for MongoDB.
|
Package mongodb contains an implementation of the `gokv.Store` interface for MongoDB. |
|
Package mysql contains an implementation of the `gokv.Store` interface for MySQL.
|
Package mysql contains an implementation of the `gokv.Store` interface for MySQL. |
|
Package postgresql contains an implementation of the `gokv.Store` interface for PostgreSQL.
|
Package postgresql contains an implementation of the `gokv.Store` interface for PostgreSQL. |
|
Package redis contains an implementation of the `gokv.Store` interface for Redis.
|
Package redis contains an implementation of the `gokv.Store` interface for Redis. |
|
Package s3 contains an implementation of the `gokv.Store` interface for Amazon S3 and other S3-compatible services.
|
Package s3 contains an implementation of the `gokv.Store` interface for Amazon S3 and other S3-compatible services. |
|
Package syncmap contains an implementation of the `gokv.Store` interface for a Go `sync.Map`.
|
Package syncmap contains an implementation of the `gokv.Store` interface for a Go `sync.Map`. |
|
Package tablestorage contains an implementation of the `gokv.Store` interface for Azure Table Storage.
|
Package tablestorage contains an implementation of the `gokv.Store` interface for Azure Table Storage. |
|
Package tablestore contains an implementation of the `gokv.Store` interface for Alibaba Cloud Table Store.
|
Package tablestore contains an implementation of the `gokv.Store` interface for Alibaba Cloud Table Store. |
|
Package test contains functions for testing `gokv.Store` implementations.
|
Package test contains functions for testing `gokv.Store` implementations. |
|
Package util contains utility functions that are used across all `gokv.Store` implementations.
|
Package util contains utility functions that are used across all `gokv.Store` implementations. |
|
Package zookeeper contains an implementation of the `gokv.Store` interface for Apache ZooKeeper.
|
Package zookeeper contains an implementation of the `gokv.Store` interface for Apache ZooKeeper. |
Click to show internal directories.
Click to hide internal directories.