websocket

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastMessage

func BroadcastMessage(msg string)

BroadcastMessage send broadcast message to channel and record stats

func HandleWebSocketCommand

func HandleWebSocketCommand(cmd string, handler func(c *WebsocketConnection, array []string))

HandleWebSocketCommand used to register command and handler

func InitWebSocket

func InitWebSocket(env *env.Env)

InitWebSocket start websocket

func ServeWs

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

ServeWs handles websocket requests from the peer.

Types

type Command

type Command struct {
}

Command struct forms different command

func (Command) AddSeed

func (command Command) AddSeed(c *WebsocketConnection, a []string)

AddSeed handle task creation by send a seed, eg: SEED http://elastic.co

func (Command) Dispatch

func (command Command) Dispatch(c *WebsocketConnection, a []string)

Dispatch just send a dispatch signal to dispatch service

func (Command) GetTask

func (command Command) GetTask(c *WebsocketConnection, a []string)

GetTask return task information by send task_id, or task field and value, eg: GET_TASK host elasticsearch.cn GET_TASK 596

func (Command) Help

func (command Command) Help(c *WebsocketConnection, a []string)

Help command returns command help information

func (Command) UpdateLogLevel

func (command Command) UpdateLogLevel(c *WebsocketConnection, a []string)

UpdateLogLevel update the logging level, usually used for debug

type Hub

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

Hub maintains the set of active connections and broadcasts messages to the connections.

type MsgType

type MsgType string

MsgType is the type of different message

const (
	// PrivateMessage means message is 1 to 1
	PrivateMessage MsgType = "PRIVATE"
	// PublicMessage means broadcast message
	PublicMessage MsgType = "PUBLIC"
	// ConfigMessage used to send configuration
	ConfigMessage MsgType = "CONFIG"
)

type WebsocketConnection

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

WebsocketConnection is an middleman between the websocket connection and the hub.

func (*WebsocketConnection) Broadcast

func (c *WebsocketConnection) Broadcast(msg string)

Broadcast public message to all channels

func (*WebsocketConnection) WriteMessage

func (c *WebsocketConnection) WriteMessage(t MsgType, msg string) error

WriteMessage will use the right way to write message, don't call c.write directly

func (*WebsocketConnection) WritePrivateMessage

func (c *WebsocketConnection) WritePrivateMessage(msg string) error

WritePrivateMessage will send msg to channel

type WebsocketHandlerFunc

type WebsocketHandlerFunc func(c *WebsocketConnection, array []string)

WebsocketHandlerFunc define the func to handle websocket

Jump to

Keyboard shortcuts

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