kv

package module
v6.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: ISC Imports: 21 Imported by: 2

README

Kilovolt

Websocket-based APIs for Badger. Does not aim to give access to all features (for the time being), mostly what's needed for strimertul and stulbe

Clients

We maintain a few libraries to interact with Kilovolt at strimertul/kilovolt-clients.

If you don't find one that suits you, just write one yourself, I promise it's really simple! See PROTOCOL.md for all you'll need to implement to make it work.

License

Most of the code here is based on Gorilla Websocket's chat example, which is licensed under BSD-2-Clause (see LICENSE-gorilla).

The entire project is licensed under ISC (see LICENSE).

Documentation

Index

Constants

View Source
const (
	CmdProtoVersion      = "version"
	CmdReadKey           = "kget"
	CmdReadBulk          = "kget-bulk"
	CmdReadPrefix        = "kget-all"
	CmdWriteKey          = "kset"
	CmdWriteBulk         = "kset-bulk"
	CmdSubscribeKey      = "ksub"
	CmdSubscribePrefix   = "ksub-prefix"
	CmdUnsubscribeKey    = "kunsub"
	CmdUnsubscribePrefix = "kunsub-prefix"
	CmdListKeys          = "klist"
	CmdAuthRequest       = "klogin"
	CmdAuthChallenge     = "kauth"
)

Commands

View Source
const (
	ErrServerError  = "server error"
	ErrInvalidFmt   = "invalid message format"
	ErrMissingParam = "required parameter missing"
	ErrUnknownCmd   = "unknown command"
	ErrAuthNotInit  = "authentication not initialized"
	ErrAuthFailed   = "authentication failed"
	ErrAuthRequired = "authentication required"
)
View Source
const ProtoVersion = "v6"

Variables

View Source
var (
	ErrClientNotFound = errors.New("client not found")
)

Functions

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)

ServeWs is the legacy handler for WS

Types

type Client

type Client interface {
	Options() ClientOptions
	Close()

	SendMessage([]byte)
	SendJSON(interface{})

	SetUID(int64)
	UID() int64
}

Client is a middleman between the websocket connection and the hub.

type ClientOptions

type ClientOptions struct {
	// Adds a prefix to all key operations to restrict them to a namespace
	Namespace string
}

ClientOptions is a list of tweakable options for clients

type ErrCode

type ErrCode string

type Error

type Error struct {
	Ok        bool    `json:"ok"`
	Error     ErrCode `json:"error"`
	Details   string  `json:"details"`
	RequestID string  `json:"request_id,omitempty"`
}

type Hello

type Hello struct {
	CmdType string `json:"type"`
	Version string `json:"version"`
}

type Hub

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

func NewHub

func NewHub(db *badger.DB, options HubOptions, logger logrus.FieldLogger) (*Hub, error)

func (*Hub) Close

func (hub *Hub) Close()

func (*Hub) CreateClient

func (hub *Hub) CreateClient(w http.ResponseWriter, r *http.Request, options ClientOptions)

CreateClient upgrades a HTTP request to websocket and makes it a client for the hub

func (*Hub) Run

func (hub *Hub) Run()

func (*Hub) SetOptions

func (hub *Hub) SetOptions(options HubOptions)

type HubOptions

type HubOptions struct {
	Password string
}

type Push

type Push struct {
	CmdType  string `json:"type"`
	Key      string `json:"key"`
	NewValue string `json:"new_value"`
}

type Request

type Request struct {
	CmdName   string                 `json:"command"`
	RequestID string                 `json:"request_id,omitempty"`
	Data      map[string]interface{} `json:"data"`
}

type Response

type Response struct {
	CmdType   string      `json:"type"`
	Ok        bool        `json:"ok"`
	RequestID string      `json:"request_id,omitempty"`
	Data      interface{} `json:"data,omitempty"`
}

type WebsocketClient

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

func (*WebsocketClient) Close

func (c *WebsocketClient) Close()

func (*WebsocketClient) Options

func (c *WebsocketClient) Options() ClientOptions

func (*WebsocketClient) SendJSON

func (c *WebsocketClient) SendJSON(data interface{})

func (*WebsocketClient) SendMessage

func (c *WebsocketClient) SendMessage(data []byte)

func (*WebsocketClient) SetUID

func (c *WebsocketClient) SetUID(uid int64)

func (*WebsocketClient) UID

func (c *WebsocketClient) UID() int64

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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