ws

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ws implements a websocket client and server for communication between the host and agents.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueFull = errors.New("Send queue full")
)

Functions

func Encode

func Encode(t Type, p interface{}) ([]byte, error)

Encode will return an encoded payload suitable for transmission over the wire

func NewService

func NewService(handlers Handlers, logMsgChan chan LogPayload) *socketService

NewService allocates and connects all websocket routes and session states

Types

type Client

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

Client provides a generic websocket client for agent connections

func NewClient

func NewClient(host string, handlers Handlers) (*Client, error)

func (*Client) Send

func (c *Client) Send(payload Payload) error

func (*Client) Start

func (c *Client) Start() error

type Handlers

type Handlers map[Type]PayloadHandler

type LogPayload

type LogPayload struct {
	ServerName string `json:"server_name"`
	Message    string `json:"message"`
}

LogPayload is the container for log/message payloads

type Payload

type Payload struct {
	Type Type            `json:"payload_type"`
	Data json.RawMessage `json:"data"`
}

type PayloadHandler

type PayloadHandler func(payload Payload) error

type Ping

type Ping struct {
	Nonce int64
}

type SocketAuthReq

type SocketAuthReq struct {
	Token      string `json:"token"`
	IsServer   bool   `json:"is_server"`
	ServerName string `json:"server_name"`
}

type Type

type Type int
const (
	OKType Type = iota
	ErrType
	Sup

	// Server <-> Server events
	SrvStart
	SrvStop
	SrvRestart
	SrvCopy
	SrvInstall
	SrvUninstall
	SrvLogRaw

	// Server <-> Web Client
	AuthType
	AuthFailType
	AuthOKType
	LogType
	LogQueryOpts
	LogQueryResults
)

type WSErrRes

type WSErrRes struct {
	Error string `json:"err"`
}

type WebSocketAuthResp

type WebSocketAuthResp struct {
	Status  bool   `json:"status"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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