Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotExist is returned when the supplied key to Get() or Delete() // does not exists in the database. ErrKeyNotExist = errors.New("store: key does not exist") // ErrBadValue is returned when the value supplied to Put() in the database // could not be encoded or is nil. ErrBadValue = errors.New("store: bad value") )
Functions ¶
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store represents the key/value store. Use the Open() method to open one, and Close() to close one.
func Open ¶
Open a key/value store. "path" is the full path to LevelDB database file. The DB will be created if not exist, unless ErrorIfMissing is true. You can pass in options to LevelDB via "o".
func (*Store) Delete ¶
Delete an entry of a given key from the store. If no such key is present in the store it will not return an error.
s.Delete(store.Byte("key42"))
func (*Store) Get ¶
Get a value from the store. "value" must be a pointer to a type, because of underlying gob. If the key is not present in the store, an ErrKeyNotExist is returned.
type MyStruct struct { Numbers []int } var val MyStruct if err := s.Get(store.Byte("key42"), &val); err == store.ErrKeyNotExist { // "key42" not found } if err != nil { // some other error occurred }
The value passed to Get() can be nil. Which gives you the same result as Exist().
if err := s.Get(store.Byte("key42"), nil); err == nil { fmt.Println("entry is present") }
func (*Store) Put ¶
Put is creating an entry in the store. It overwrites any previous existing value for the given key. The passed value is gob-encoded and stored. The value cannot be nil and Put() returns an ErrBadValue.
err := s.Put(store.Byte("key42"), 42) err := s.Put(store.Byte("key42"), "the question to live and the universe.") m := map[string]int{ "foo": 0, "bar": 1 } err := s.Put(store.Byte("key42"), m)