package module
v1.6.1 Latest Latest

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

Go to latest
Published: Jul 7, 2020 License: MIT Imports: 5 Imported by: 0



goukv is an abstraction layer for golang based key-value stores, it is easy to add any backend provider.

Available Providers


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 replaces has().


package main

import (
    _ "github.com/alash3al/goukv/providers/goleveldb"

func main() {
    db, err := goukv.Open("leveldb", "./")

    if err != nil {

    defer db.Close()

        Key: []byte("k1"),
        Value: []byte("v1"),
        TTL: time.Second * 10,





This section is empty.


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


func Register

func Register(name string, provider Provider) error

Register register a new driver


type DSN added in v1.6.0

type DSN struct {
	// contains filtered or unexported fields

DSN data source name

func NewDSN added in v1.6.0

func NewDSN(dsn string) (*DSN, error)

NewDSN initializes a new dsn by parsing the specified dsn

func (DSN) GetBool added in v1.6.0

func (dsn DSN) GetBool(key string) bool

GetInt returns the value of the key as bool

func (DSN) GetFloat added in v1.6.0

func (dsn DSN) GetFloat(key string) float64

GetInt returns the value of the key as float64

func (DSN) GetInt added in v1.6.0

func (dsn DSN) GetInt(key string) int

GetInt returns the value of the key as int

func (DSN) GetInt64 added in v1.6.0

func (dsn DSN) GetInt64(key string) int64

GetInt returns the value of the key as int64

func (DSN) GetString added in v1.6.0

func (dsn DSN) GetString(key string) string

GetString fetches an option from the options as string

func (DSN) Hostname added in v1.6.0

func (dsn DSN) Hostname() string

Hostname returns the dsn hostname

func (DSN) Password added in v1.6.0

func (dsn DSN) Password() string

Password returns the password

func (DSN) Path added in v1.6.0

func (dsn DSN) Path() string

Path returns the dsn path

func (DSN) Port added in v1.6.0

func (dsn DSN) Port() string

Port returns the dsn port number as string

func (DSN) Scheme added in v1.6.0

func (dsn DSN) Scheme() string

Scheme returns the dsn scheme

func (DSN) Username added in v1.6.0

func (dsn DSN) Username() string

Username returns the dsn username

type Entry

type Entry struct {
	Key   []byte
	Value []byte
	TTL   time.Duration

Entry represents a key - value pair

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

func Get

func Get(providerName string) (Provider, error)

Get returns a driver from the registery

func Open

func Open(providerName, dsn string) (Provider, error)

Open initialize the specified provider and returns its instance

type ScanOpts

type ScanOpts struct {
	Prefix        []byte
	Offset        []byte
	Scanner       Scanner
	IncludeOffset bool
	ReverseScan   bool

ScanOpts scanner options

type Scanner

type Scanner func([]byte, []byte) bool

Scanner a function that performs the scanning/filterig


Path Synopsis

Jump to

Keyboard shortcuts

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