README

Overview

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

Available Providers

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

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")))
}

Expand ▾ Collapse ▴

Documentation

Index

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

    func Register

    func Register(name string, provider Provider) error

      Register register a new driver

      Types

      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

                                            Directories

                                            Path Synopsis
                                            providers