kv

package module
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: ISC Imports: 10 Imported by: 0

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"
	CmdWriteKey       = "kset"
	CmdSubscribeKey   = "ksub"
	CmdUnsubscribeKey = "kunsub"
)

Commands

View Source
const (
	ErrInvalidFmt   = "invalid message format"
	ErrMissingParam = "required parameter missing"
	ErrUpdateFailed = "server update failed"
	ErrUnknownCmd   = "unknown command"
)
View Source
const ProtoVersion = "v2"

Variables

This section is empty.

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 struct {
	// contains filtered or unexported fields
}

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

type ClientOptions added in v2.1.0

type ClientOptions struct {
	// RemapKeyFn is a optional function for remapping keys so they can be namespaced properly
	RemapKeyFn func(key string) string
}

ClientOptions is a list of tweakable options for clients

type ErrCode

type ErrCode string

type Error added in v2.1.1

type Error struct {
	Ok      bool    `json:"ok"`
	Error   ErrCode `json:"error"`
	Details string  `json:"details"`
	Cmd     string  `json:"cmd"`
}

type Hub

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

func NewHub

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

func (*Hub) CreateClient added in v2.1.0

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) ReadKey

func (h *Hub) ReadKey(key string) (string, error)

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) WriteKey

func (h *Hub) WriteKey(key string, data string) error

type Push added in v2.1.1

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

type Request added in v2.1.1

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

type Response added in v2.1.1

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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