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 (
    _ ""

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

    if err != nil {

    defer db.Close()

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


Expand ▾ Collapse ▴




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

      type DSN struct {
      	// contains filtered or unexported fields

        DSN data source name

        func NewDSN

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

          NewDSN initializes a new dsn by parsing the specified dsn

          func (DSN) GetBool

          func (dsn DSN) GetBool(key string) bool

            GetInt returns the value of the key as bool

            func (DSN) GetFloat

            func (dsn DSN) GetFloat(key string) float64

              GetInt returns the value of the key as float64

              func (DSN) GetInt

              func (dsn DSN) GetInt(key string) int

                GetInt returns the value of the key as int

                func (DSN) GetInt64

                func (dsn DSN) GetInt64(key string) int64

                  GetInt returns the value of the key as int64

                  func (DSN) GetString

                  func (dsn DSN) GetString(key string) string

                    GetString fetches an option from the options as string

                    func (DSN) Hostname

                    func (dsn DSN) Hostname() string

                      Hostname returns the dsn hostname

                      func (DSN) Password

                      func (dsn DSN) Password() string

                        Password returns the password

                        func (DSN) Path

                        func (dsn DSN) Path() string

                          Path returns the dsn path

                          func (DSN) Port

                          func (dsn DSN) Port() string

                            Port returns the dsn port number as string

                            func (DSN) Scheme

                            func (dsn DSN) Scheme() string

                              Scheme returns the dsn scheme

                              func (DSN) Username

                              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