client

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: GPL-3.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MsgOk      = "ok"
	MsgError   = "error"
	MsgDone    = "done"
	MsgSuccess = "success"
	MsgUpdate  = "upd"
	MsgNew     = "new"
	MsgDelete  = "del"
	MsgWarning = "warning"

	MsgOffline = "offline" // special message type for signaling the handler that the connection was lost

)

Message Types.

Variables

View Source
var (
	ErrMalformedMessage = errors.New("malformed message")
)

Client errors.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

The Client enables easy interaction with the API.

func NewClient

func NewClient(server string) *Client

NewClient returns a new Client.

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to the API once.

func (*Client) Create

func (c *Client) Create(key string, value interface{}, handleFunc func(*Message)) *Operation

Create sends a create command to the API.

func (*Client) Delete

func (c *Client) Delete(key string, handleFunc func(*Message)) *Operation

Delete sends a delete command to the API.

func (*Client) Get

func (c *Client) Get(key string, handleFunc func(*Message)) *Operation

Get sends a get command to the API.

func (*Client) Insert

func (c *Client) Insert(key string, value interface{}, handleFunc func(*Message)) *Operation

Insert sends an insert command to the API.

func (*Client) NewOperation

func (c *Client) NewOperation(handleFunc func(*Message)) *Operation

NewOperation returns a new operation.

func (*Client) Offline

func (c *Client) Offline() <-chan struct{}

Offline returns a closed channel read if the client is not connected to the API.

func (*Client) Online

func (c *Client) Online() <-chan struct{}

Online returns a closed channel read if the client is connected to the API.

func (*Client) Qsub

func (c *Client) Qsub(query string, handleFunc func(*Message)) *Operation

Qsub sends a qsub command to the API.

func (*Client) Query

func (c *Client) Query(query string, handleFunc func(*Message)) *Operation

Query sends a query command to the API.

func (*Client) Shutdown

func (c *Client) Shutdown()

Shutdown shuts the client down.

func (*Client) StayConnected

func (c *Client) StayConnected()

StayConnected calls Connect again whenever the connection is lost.

func (*Client) Sub

func (c *Client) Sub(query string, handleFunc func(*Message)) *Operation

Sub sends a sub command to the API.

func (*Client) Update

func (c *Client) Update(key string, value interface{}, handleFunc func(*Message)) *Operation

Update sends an update command to the API.

type Message

type Message struct {
	OpID     string
	Type     string
	Key      string
	RawValue []byte
	Value    interface{}
	// contains filtered or unexported fields
}

Message is an API message.

func ParseMessage

func ParseMessage(data []byte) (*Message, error)

ParseMessage parses the given raw data and returns a Message.

func (*Message) Pack

func (m *Message) Pack() ([]byte, error)

Pack serializes a message into a []byte slice.

type Operation

type Operation struct {
	ID string
	// contains filtered or unexported fields
}

Operation represents a single operation by a client.

func (*Operation) Cancel

func (op *Operation) Cancel()

Cancel the operation.

func (*Operation) EnableResuscitation

func (op *Operation) EnableResuscitation()

EnableResuscitation will resend the request after reconnecting to the API.

func (*Operation) Send

func (op *Operation) Send(command, text string, data interface{})

Send sends a request to the API.

Jump to

Keyboard shortcuts

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