kvs

package
v0.0.0-...-276be26 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: MIT Imports: 3 Imported by: 0

README

kvs - K/V Store Layer

It's an abstract layer for common operations of K/V stores like:

  1. consul
  2. etcd

TODO to support more backends could be a scheduling plan.

Usages

Main interface is lied in store.KVStore

We make new store.KVStore with kvs.New() call:


store := kvs.New(&consul_util.ConsulConfig{
    Scheme: "http",
    Addr: "127.0.0.1:8500",
    Insecure: true,
    CertFile: "", KeyFile: "", CACertFile: "",
    Username: "", Password: "",
    Root: "",
    DeregisterCriticalServiceAfter: "30s",
})
defer store.Close() // optional

// or
storeEtcd := kvs.New(
    &etcd.Etcdtool{
        Peers: "127.0.0.1:2379",
        Cert: "",
        Key: "", CA: "", User: "",
        Timeout: time.Second * 10,
        CommandTimeout: time.Second * 5,
        Routes: []etcd.Route{},
        PasswordFilePath: "",
        Root: "",
    }
)
defer storeEtcd.Close() // optional

Once store got, we can get/set key/value pair:

store.Put("x", "yz")
log.Info(store.Get("x"))

// Or, with yaml encode/decode transparently
state := map[string]string{
    "ab": "111",
    "cd": "222",
}
store.PutYaml("state", state)
state1 := store.GetYaml("state")
log.Infof("state1: %v", state1)

// And, with path separatly
store.Put("config/gwapi/enabled", "true")

// And, delete them:
store.Delete("x")
store.Delete("state")
store.Delete("config/gwapi")

For more usages, see also consul/core_test.go and etcd/i_test.go, ....

Documentation

Index

Constants

View Source
const (
	STORE_ETCD = iota
	STORE_CONSUL
)

Variables

This section is empty.

Functions

func New

func New(e interface{}) store.KVStore

func NewConsul

func NewConsul(e *store.ConsulConfig) store.KVStore

func NewETCD

func NewETCD(e *store.Etcdtool) store.KVStore

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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