ukvs

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

README

ukvs

Key-Value store with REST API

The state of this project is alpha. Dont expect any stability or consistency until version v1

Quick-Start

  1. Download and extract the latest release.

  2. Rename config.example.conf to config.conf

  3. Run the server

    $ ./ukvs
    

    With the default configuration the server will listen on 127.0.0.1:8282 with a memory only storage.

  4. Try some methods

    $ curl -X PUT -d "Hello World" http://127.0.0.1:8282/hello
    $ curl http://127.0.0.1:8282/hello
    $ curl -X DELETE http://127.0.0.1:8282/hello
    

Configuration

The config.exmaple.conf contains relatively detailed information about all settings. More practical examples will follow.

In the default configuration, the values are set so that the server provides as little information as possible. This includes disabling the server banner, limiting error output, and disabling the output of a key's meta information.

Methods

Method Description
PUT set data
GET get data
HEAD get meta-info
DELETE delete

Client

There is also a client available. See examples/client for usage.

License

GNU

Documentation

Index

Constants

View Source
const (
	LogLevelNone = 0

	LogLevelError = 10
	LogLevelWarn  = 20

	LogLevelInfo  = 100
	LogLevelDebug = 200
	LogLevelTrace = 200
)
View Source
const (
	ValueHeader_Etag      = 1 << iota
	ValueHeader_Created   = 2 << iota
	ValueHeader_LastRead  = 3 << iota
	ValueHeader_LastWrite = 4 << iota
	ValueHeader_Reads     = 5 << iota
	ValueHeader_Writes    = 6 << iota
)
View Source
const (
	CompressionZLib = 0
)
View Source
const DEFAULT_LISTEN_PORT = 48282
View Source
const SeverAuthDefaultRealm = "Authentication required"
View Source
const ValueHeaderFlag_ContentType = 1
View Source
const ValueHeaderSize = 4 + 8 + 8 + 8 + 8 + 8 + 4

Variables

View Source
var Endianess = binary.BigEndian

Functions

func PrintHexView

func PrintHexView(input []byte, bytesPerRow int)

func SetLogLevel

func SetLogLevel(level int)

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication() (app *Application)

func (*Application) GetServerByRoot

func (app *Application) GetServerByRoot(path string) *Server

func (*Application) Load

func (app *Application) Load() error

func (*Application) Start

func (app *Application) Start() (err error)

func (*Application) Stop

func (app *Application) Stop() error

type ConfigStringSet

type ConfigStringSet map[string]bool

func (ConfigStringSet) Contains

func (m ConfigStringSet) Contains(key string) bool

func (ConfigStringSet) Delete

func (m ConfigStringSet) Delete(key string)

func (ConfigStringSet) Get

func (m ConfigStringSet) Get(key string) bool

func (ConfigStringSet) Keys

func (m ConfigStringSet) Keys() (keys []string)

func (ConfigStringSet) Set

func (m ConfigStringSet) Set(key string, value bool)

func (ConfigStringSet) String

func (m ConfigStringSet) String() string

type FileStorage

type FileStorage struct {
	// contains filtered or unexported fields
}

func NewFileStorage

func NewFileStorage() *FileStorage

func (*FileStorage) Close

func (c *FileStorage) Close() error

func (*FileStorage) CollectKeys

func (c *FileStorage) CollectKeys(keymap Keymap)

func (*FileStorage) Config

func (*FileStorage) Delete

func (s *FileStorage) Delete(key Key) error

func (*FileStorage) Get

func (c *FileStorage) Get(key Key) (*Value, error)

func (*FileStorage) Has

func (c *FileStorage) Has(key Key) bool

func (*FileStorage) Head

func (c *FileStorage) Head(key Key) (*Value, error)

func (*FileStorage) KeyCount

func (c *FileStorage) KeyCount() int

func (*FileStorage) Keys

func (c *FileStorage) Keys() (keys []Key)

func (*FileStorage) Open

func (c *FileStorage) Open() error

func (*FileStorage) Set

func (s *FileStorage) Set(key Key, value *Value) error

func (*FileStorage) SetHead added in v0.1.6

func (s *FileStorage) SetHead(key Key, value *Value) error

func (*FileStorage) Size

func (c *FileStorage) Size() int64

func (*FileStorage) Start

func (c *FileStorage) Start() error

func (*FileStorage) Stop

func (c *FileStorage) Stop() error

type FileStorageChunk

type FileStorageChunk struct {
	// contains filtered or unexported fields
}

func (*FileStorageChunk) String

func (c *FileStorageChunk) String() string

type IPNetMap

type IPNetMap map[*net.IPNet]bool

func (IPNetMap) Contains

func (m IPNetMap) Contains(ip net.IP) bool

type Key

type Key string

func (Key) Hash

func (k Key) Hash() string

type KeySetForbiddenError

type KeySetForbiddenError struct {
	// contains filtered or unexported fields
}

func NewKeySetForbiddenError

func NewKeySetForbiddenError(message string) *KeySetForbiddenError

func (*KeySetForbiddenError) Error

func (e *KeySetForbiddenError) Error() string

type Keymap

type Keymap map[Key]bool

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

func NewListener

func NewListener() *Listener

func (*Listener) Address

func (l *Listener) Address() string

func (*Listener) ParseAddress

func (l *Listener) ParseAddress(address string) (err error)

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) CollectKeys

func (c *MemoryStorage) CollectKeys(keymap Keymap)

func (*MemoryStorage) Config

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(key Key) error

func (*MemoryStorage) Get

func (s *MemoryStorage) Get(key Key) (*Value, error)

func (*MemoryStorage) Has

func (s *MemoryStorage) Has(key Key) bool

func (*MemoryStorage) Head

func (c *MemoryStorage) Head(key Key) (*Value, error)

func (*MemoryStorage) KeyCount

func (c *MemoryStorage) KeyCount() int

func (*MemoryStorage) Keys

func (c *MemoryStorage) Keys() (keys []Key)

func (*MemoryStorage) Set

func (s *MemoryStorage) Set(key Key, value *Value) error

func (*MemoryStorage) SetHead added in v0.1.6

func (s *MemoryStorage) SetHead(key Key, value *Value) error

func (*MemoryStorage) Size

func (s *MemoryStorage) Size() int64

func (*MemoryStorage) Start

func (c *MemoryStorage) Start() error

func (*MemoryStorage) Stop

func (c *MemoryStorage) Stop() error

type MetricsServer

type MetricsServer struct {
	// contains filtered or unexported fields
}

func NewMetricsServer

func NewMetricsServer(app *Application) *MetricsServer

func (*MetricsServer) Start

func (s *MetricsServer) Start()

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(serveMux *http.ServeMux) *Server

func (*Server) Root

func (s *Server) Root() string

func (*Server) Start

func (s *Server) Start(app *Application) (err error)

func (*Server) Stop

func (s *Server) Stop() (err error)

func (*Server) Storage

func (s *Server) Storage() *StorageController

type ServerAuth

type ServerAuth struct {
	// contains filtered or unexported fields
}

func NewServerAuth

func NewServerAuth() *ServerAuth

type ServerMetrics

type ServerMetrics struct {
	Requests           uint64
	RequestsPerMethod  map[string]uint64
	RequestStatusCodes map[int]uint64
}

func NewServerMetrics

func NewServerMetrics() *ServerMetrics

func (*ServerMetrics) CountRequest

func (m *ServerMetrics) CountRequest(req *http.Request)

func (*ServerMetrics) CountStatus

func (m *ServerMetrics) CountStatus(code int)

type SharedStorageConfiguration

type SharedStorageConfiguration struct {
	// contains filtered or unexported fields
}

type Storage

type Storage interface {
	Config() *SharedStorageConfiguration
	Start() error
	Stop() error
	KeyCount() int
	CollectKeys(keymap Keymap)
	Keys() []Key
	Has(key Key) bool
	Head(key Key) (*Value, error)
	Get(key Key) (*Value, error)
	Set(key Key, value *Value) error
	SetHead(key Key, value *Value) error
	Delete(key Key) error
	Size() int64
}

type StorageChain

type StorageChain struct {
	// contains filtered or unexported fields
}

func NewStorageChain

func NewStorageChain() *StorageChain

func (*StorageChain) CollectKeys

func (c *StorageChain) CollectKeys(keymap Keymap)

func (*StorageChain) Config

func (*StorageChain) Delete

func (c *StorageChain) Delete(key Key) error

func (*StorageChain) Get

func (c *StorageChain) Get(key Key) (value *Value, err error)

func (*StorageChain) Has

func (c *StorageChain) Has(key Key) bool

func (*StorageChain) Head

func (c *StorageChain) Head(key Key) (*Value, error)

func (*StorageChain) KeyCount

func (c *StorageChain) KeyCount() int

func (*StorageChain) Keys

func (c *StorageChain) Keys() (keys []Key)

func (*StorageChain) Set

func (c *StorageChain) Set(key Key, value *Value) error

func (*StorageChain) SetHead added in v0.1.6

func (c *StorageChain) SetHead(key Key, value *Value) error

func (*StorageChain) Size

func (c *StorageChain) Size() (size int64)

func (*StorageChain) Start

func (c *StorageChain) Start() error

func (*StorageChain) Stop

func (c *StorageChain) Stop() error

func (*StorageChain) Storages

func (c *StorageChain) Storages() []Storage

type StorageController

type StorageController struct {
	// contains filtered or unexported fields
}

func NewStorageController

func NewStorageController() *StorageController

func (*StorageController) Chain

func (c *StorageController) Chain() *StorageChain

func (*StorageController) CollectKeys

func (c *StorageController) CollectKeys(keymap Keymap)

func (*StorageController) Delete

func (c *StorageController) Delete(key Key) error

func (*StorageController) Get

func (c *StorageController) Get(key Key) (value *Value, err error)

func (*StorageController) Has

func (c *StorageController) Has(key Key) bool

func (*StorageController) Head

func (c *StorageController) Head(key Key) (value *Value, err error)

func (*StorageController) Set

func (c *StorageController) Set(key Key, value *Value) error

func (*StorageController) Size

func (c *StorageController) Size() (size int64)

func (*StorageController) Start

func (c *StorageController) Start() error

func (*StorageController) Stop

func (c *StorageController) Stop() error

type Value

type Value struct {
	ValueHeader
	Data []byte
}

func NewValue

func NewValue(data []byte) *Value

func (*Value) BinarySize

func (v *Value) BinarySize() uint32

func (*Value) Read

func (s *Value) Read(r io.Reader) error

func (*Value) ReadResponse

func (value *Value) ReadResponse(response *http.Response, skipData bool) error

func (*Value) Write

func (s *Value) Write(w io.Writer) error

type ValueHeader

type ValueHeader struct {
	Flags     uint32
	Created   time.Time
	LastRead  time.Time
	LastWrite time.Time
	Reads     uint64
	Writes    uint64
	DataSize  uint32
}

func (*ValueHeader) Read

func (s *ValueHeader) Read(r io.Reader) error

func (*ValueHeader) Write

func (s *ValueHeader) Write(w io.Writer) error

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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