websocket

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FatalWebsocketError error = errors.New("fatal websocket error")

Functions

func HandleWebsocket

func HandleWebsocket(conn net.Conn)

HandleWebsocket handles the websocket connections.

Types

type HistoryRequestParameters

type HistoryRequestParameters struct {
	From       time.Time   `json:"from,omitempty"`
	Until      time.Time   `json:"until,omitempty"`
	MaxDensity interface{} `json:"max_density,omitempty"`
}

HistoryRequestParameters is a model for paramters that can be set with HIST requests.

type Message

type Message struct {
	OpCode OpCode        `json:"op"`
	Target TargetAddress `json:"target"`
	Value  string        `json:"value,omitempty"`
}

Message is the model for a websocket message.

func NewMessage

func NewMessage(opcode OpCode, target TargetAddress, value string) Message

NewMessage returns a Message with chosen OpCode, TargetAddress and value.

func (Message) Bytes

func (msg Message) Bytes() ([]byte, error)

Bytes converts a Message to JSON and returns it as a byte slice.

type OpCode

type OpCode string

The OpCode type is used to identify the different operations possible.

const (
	GET   OpCode = "GET"
	SUB   OpCode = "SUB"
	UNSUB OpCode = "UNSUB"
	HIST  OpCode = "HIST"
	REPLY OpCode = "REPLY"
	ERR   OpCode = "ERR"
)

type TargetAddress

type TargetAddress string

TargetAddress models the target field in websocket messages

func GetEmptyTarget

func GetEmptyTarget() TargetAddress

GetEmptyTarget returns an empty TargetAddress. This is used whenever a message needs to be sent that cannot be assigned to a specific target. I.e. whenever there is no target specified in an erroneous request

Jump to

Keyboard shortcuts

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