README
Overview
goukv
is an abstraction layer for golang based key-value stores, it is easy to add any backend provider.
Available Providers
badgerdb
: BadgerDBgolveldb
: GolevelDBpostgres
: Postgresql
Why
I just built this to be used in my side projects such as redix(v2), but you can use it with no worries, it is production-ready, and I'm open for any idea & contribution.
Backend Stores Rules
just keep it simple stupid!
- Use the
map[string]interface{}
as your options. Nil
value means DELETE.- Respect the
Entry
struct. - Respect the
ScanOpts
struct. - On key not found, return
goukv.ErrKeyNotFound
, this replaceshas()
.
Example
package main
import (
"time"
"fmt"
"github.com/alash3al/goukv"
_ "github.com/alash3al/goukv/providers/goleveldb"
)
func main() {
db, err := goukv.Open("leveldb", "./")
if err != nil {
panic(err.Error())
}
defer db.Close()
db.Put(&goukv.Entry{
Key: []byte("k1"),
Value: []byte("v1"),
TTL: time.Second * 10,
})
fmt.Println(db.Get([]byte("k1")))
}
Documentation
Index ¶
- Variables
- func Register(name string, provider Provider) error
- type DSN
- func (dsn DSN) GetBool(key string) bool
- func (dsn DSN) GetFloat(key string) float64
- func (dsn DSN) GetInt(key string) int
- func (dsn DSN) GetInt64(key string) int64
- func (dsn DSN) GetString(key string) string
- func (dsn DSN) Hostname() string
- func (dsn DSN) Password() string
- func (dsn DSN) Path() string
- func (dsn DSN) Port() string
- func (dsn DSN) Scheme() string
- func (dsn DSN) Username() string
- type Entry
- type Provider
- type ScanOpts
- type Scanner
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDriverAlreadyExists = errors.New("the specified driver name is already exisrs") ErrDriverNotFound = errors.New("the requested driver isn't found") ErrKeyExpired = errors.New("the specified key is expired") ErrKeyNotFound = errors.New("the specified key couldn't be found") )
error related variables
Functions ¶
Types ¶
type DSN ¶
type DSN struct {
// contains filtered or unexported fields
}
DSN data source name
type Provider ¶
type Provider interface { Open(*DSN) (Provider, error) Put(*Entry) error Get([]byte) ([]byte, error) TTL([]byte) (*time.Time, error) Delete([]byte) error Batch([]*Entry) error Scan(ScanOpts) error Close() error }
Provider an interface describes a storage backend