netkv

package module
v0.0.0-...-f3447b8 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

README

netkv - A networked key/value store

netkv enables building client and server applications that are based on a networked key/value store. The central idea around netkv is that all resources and services can be presented through a key/value interface. All interactions across the network are performed with troposphere messages.

See troposphere here: https://gitlab.com/pbohun/troposphere

Status

Unstable. The API to this library may change.

Requirements

  • Go 1.24.4 or greater

Usage

See included examples directory. To build examples, cd into the example directory you wish to build and run the following commands:

go build server.go
go build client.go

Four Actions

There are four possible actions a client connection can make:

  • SET: setting a key and value association
  • GET: retreiving a value from a given key
  • DEL: deleting an association with the given key
  • TXN: executing a transaction with the given key and data

Structured Keys

netkv supports the troposphere standard of structured keys. Keys are utf8 strings with no whitespace, but there are two reserved characters that have special meaning: / and *.

  • / is used as a "path separator" just as in unix file paths or url paths
  • * is used as a wildcard character that can only exist at the end of a key

The asterisk can be used in GET and DEL actions to address multiple key/value relations. For example, using GET with the key /people/bob/* will retreive the list of all keys that match the prefix /people/bob/. This includes /people/bob/hair-color, /people/bob/salary, and any other keys that have the given prefix. Without an asterisk, a key will only match one key in the system.

Two Responses

A server can only produce two types of messages in response to a client:

  • DAT: A data message that indicates success and may carry data if requested
  • ERR: An error message that contains a description of the error

License

BSD-3-Clause

Unofficial Theme Song

"Ships in the Night" ~Mat Kearney

https://www.youtube.com/watch?v=BCkfTCjF8SM

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

func NewConnection

func NewConnection(privkey string) *Connection

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) Delete

func (c *Connection) Delete(key string) error

func (*Connection) Dial

func (c *Connection) Dial(addr string) error

func (*Connection) Get

func (c *Connection) Get(key string) (string, error)

func (*Connection) Set

func (c *Connection) Set(key, val string) error

func (*Connection) Transact

func (c *Connection) Transact(key, val string) (string, error)

type Server

type Server struct {
	WebDir    string
	Authorize func(m tro.Message) bool
	ExecMap   map[string][]string
	Services  map[string]Service
	// contains filtered or unexported fields
}

func (*Server) AddService

func (s *Server) AddService(key string, service Service)

func (*Server) CloseDB

func (s *Server) CloseDB()

func (*Server) Del

func (s *Server) Del(m tro.Message) error

func (*Server) Get

func (s *Server) Get(m tro.Message) (string, error)

func (*Server) Listen

func (s *Server) Listen(port string) error

func (*Server) OpenSQLite

func (s *Server) OpenSQLite(filename string) error

func (*Server) Set

func (s *Server) Set(m tro.Message) error

func (*Server) SetDB

func (s *Server) SetDB(db *sql.DB) error

func (*Server) Txn

func (s *Server) Txn(m tro.Message) (string, error)

type Service

type Service func(s *Server, data string) (string, error)

Directories

Path Synopsis
examples
perms-kv command
service-kv command
simple-kv command

Jump to

Keyboard shortcuts

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