store

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package store handles interaction with the backing store.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoBackingStore = errors.New("no backing store set")

ErrNoBackingStore is returned if no backing store is set on the Locking store.

Functions

This section is empty.

Types

type GetSetter added in v0.1.5

type GetSetter interface {
	Getter
	Setter
}

GetSetter types can Get and Set from a store.

type Getter added in v0.1.5

type Getter interface {
	// Get data from the backing store.
	Get(key string) (string, error)
}

Getter types can get data from the backing store.

type JSONStore added in v0.1.5

type JSONStore struct {
	BackingStore GetSetter
}

JSONStore stores JSON documents, converting them to strings for the backing store.

func (*JSONStore) Get added in v0.1.5

func (j *JSONStore) Get(key string, i interface{}) error

Get data from JSON stored in the backing store, marshalling the JSON into the given pointer.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/store"
)

func main() {
	var out string

	s := store.JSONStore{BackingStore: &store.Memory{}}

	_ = s.Set("k", "in")
	_ = s.Get("k", &out)

	fmt.Println(out)

}
Output:

in

func (*JSONStore) Set added in v0.1.5

func (j *JSONStore) Set(key string, i interface{}) error

Set a type in the store marshalling it to JSON for storage.

type Locking added in v0.1.5

type Locking struct {
	BackingStore GetSetter
	// contains filtered or unexported fields
}

Locking store single threads access to a store.

func (*Locking) Get added in v0.1.5

func (l *Locking) Get(key string) (string, error)

Get data from the store. The store is locked while being accessed.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/store"
)

func main() {
	s := store.Locking{BackingStore: &store.Memory{}}

	_ = s.Set("k", "v")

	v, _ := s.Get("k")

	fmt.Println(v)

}
Output:

v

func (*Locking) Set added in v0.1.5

func (l *Locking) Set(key string, data string) error

Set data on the store. The store is locked while being accessed.

type Memory added in v0.1.5

type Memory struct {
	// contains filtered or unexported fields
}

Memory store primarily used for testing.

func (*Memory) Get added in v0.1.5

func (m *Memory) Get(key string) (string, error)

Get data from the in memory store.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/store"
)

func main() {
	s := store.Memory{}

	_ = s.Set("k", "v")
	v, _ := s.Get("k")

	fmt.Println(v)

}
Output:

v

func (*Memory) Set added in v0.1.5

func (m *Memory) Set(key, data string) error

Set data into the in memory store.

type Setter added in v0.1.5

type Setter interface {
	// Set data in the store on the given key.
	Set(key, data string) error
}

Setter types can set data into the backing store.

Directories

Path Synopsis
Package aws handles using AWS as the backing store.
Package aws handles using AWS as the backing store.

Jump to

Keyboard shortcuts

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