datastore

package
v0.0.0-...-73638bf Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundEntry             = errors.New("not found entry")
	ErrInvalidEntry              = errors.New("invalid entry")
	ErrNotMatchTypeMessage       = errors.New("not match type message")
	ErrNotMatchTypeMessageStatus = errors.New("not match type message status")
	ErrNotMatchTypeSubscription  = errors.New("not match type subscription")
	ErrNotMatchTypeTopic         = errors.New("not match type topic")
	ErrNotSupportOperation       = errors.New("not support operation")
	ErrNotSupportDriver          = errors.New("not support driver")
)

datastore errors

Functions

func EncodeGob

func EncodeGob(s interface{}) ([]byte, error)

EncodeGob return encoeded bytes by gob

func SetGlobalConfig

func SetGlobalConfig(cfg *Config)

SetGlobalConfig set global config

func SpecifyDump

func SpecifyDump(d Datastore, key string) (map[interface{}]interface{}, error)

SpecifyDump return Dump entries, each Datastore type

Types

type Config

type Config struct {
	Redis *RedisConfig `yaml:"redis"`
	MySQL *MySQLConfig `yaml:"mysql"`
}

Config is specific datastore config, written under "datastore"

var GlobalConfig *Config

GlobalConfig keep config TODO: abort global variables

type Datastore

type Datastore interface {
	Set(key, value interface{}) error
	Get(key interface{}) (interface{}, error)
	Delete(key interface{}) error
	Dump() (map[interface{}]interface{}, error)
}

Datastore is behavior like Key-Value store

func LoadDatastore

func LoadDatastore(cfg *Config) (Datastore, error)

LoadDatastore load backend datastore from cnofiguration json file.

type Memory

type Memory struct {
	Store map[interface{}]interface{}
	// contains filtered or unexported fields
}

Memory is datastore driver for "in memory"

func NewMemory

func NewMemory(_ *Config) *Memory

NewMemory create memory object

func (*Memory) Delete

func (m *Memory) Delete(key interface{}) error

Delete delete item

func (*Memory) Dump

func (m *Memory) Dump() (map[interface{}]interface{}, error)

Dump dump store values

func (*Memory) Get

func (m *Memory) Get(key interface{}) (interface{}, error)

Get get item

func (*Memory) Set

func (m *Memory) Set(key, value interface{}) error

Set save item

type MySQL

type MySQL struct {
	Conn *sql.DB
}

MySQL is MySQL datastore driver

func NewMySQL

func NewMySQL(cfg *Config) (*MySQL, error)

NewMySQL return MySQL client

func (*MySQL) Delete

func (m *MySQL) Delete(key interface{}) error

Delete delete item

func (*MySQL) Dump

func (m *MySQL) Dump() (map[interface{}]interface{}, error)

Dump return stored items

func (*MySQL) DumpPrefix

func (m *MySQL) DumpPrefix(p string) (map[interface{}]interface{}, error)

DumpPrefix return stored items when match prefix key

func (*MySQL) Get

func (m *MySQL) Get(key interface{}) (interface{}, error)

Get get item

func (*MySQL) Set

func (m *MySQL) Set(key, value interface{}) error

Set save item

type MySQLConfig

type MySQLConfig struct {
	Addr     string `yaml:"addr"`
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

MySQLConfig represent config for the MySQL

type Redis

type Redis struct {
	Pool *redis.Pool
}

Redis is datastore driver for redis

func NewRedis

func NewRedis(cfg *Config) (*Redis, error)

NewRedis return redis client

func (*Redis) Delete

func (r *Redis) Delete(key interface{}) error

Delete delete item

func (*Redis) Dump

func (r *Redis) Dump() (map[interface{}]interface{}, error)

Dump return stored items

func (*Redis) DumpPrefix

func (r *Redis) DumpPrefix(p string) (map[interface{}]interface{}, error)

DumpPrefix return stored items when match prefix key

func (*Redis) Get

func (r *Redis) Get(key interface{}) (interface{}, error)

Get get item

func (*Redis) Set

func (r *Redis) Set(key, value interface{}) error

Set save item

type RedisConfig

type RedisConfig struct {
	Addr     string `yaml:"addr"`
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	DB       int    `yaml:"db"`
	Password string `yaml:"password"`
}

RedisConfig represent config for the Redis

Jump to

Keyboard shortcuts

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