hub

package
v0.0.0-...-15e17f2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn     ConnectionInterface
	Send     chan Message
	Producer kafka.Producer
}

func (*Client) CloseSend

func (c *Client) CloseSend() error

func (*Client) GetConnection

func (c *Client) GetConnection() ConnectionInterface

func (*Client) ReadMessage

func (c *Client) ReadMessage() (int, []byte, error)

func (*Client) ReadPump

func (c *Client) ReadPump(hub TheHub, logger Logger)

func (*Client) SendMessage

func (c *Client) SendMessage(msg Message) error

func (*Client) WritePump

func (c *Client) WritePump(logger Logger)

type ClientInterface

type ClientInterface interface {
	ReadPump(hub TheHub, logger Logger)
	WritePump(logger Logger)
	GetConnection() ConnectionInterface
	SendMessage(msg Message) error
	CloseSend() error
}

type ConnectionInterface

type ConnectionInterface interface {
	Close() error
	WriteMessage(int, []byte) error
	ReadMessage() (int, []byte, error)
}

type Hub

type Hub struct {
	Clients    map[ClientInterface]bool
	Broadcast  chan Message
	Register   chan ClientInterface
	Unregister chan ClientInterface

	Logger Logger

	SaramaConfig *sarama.Config
	// contains filtered or unexported fields
}

func (*Hub) BroadcastMessage

func (h *Hub) BroadcastMessage(message Message)

func (*Hub) HandleWebSocketMessage

func (h *Hub) HandleWebSocketMessage(message Message)

func (*Hub) IsTest

func (h *Hub) IsTest(isTest bool)

func (*Hub) RegisterClient

func (h *Hub) RegisterClient(client ClientInterface)

func (*Hub) Run

func (h *Hub) Run(ctx context.Context, logger Logger)

func (*Hub) UnregisterClient

func (h *Hub) UnregisterClient(client ClientInterface)

func (*Hub) UpgradeWebSocket

func (h *Hub) UpgradeWebSocket(c *websocket.Conn, logger Logger)

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

type Message

type Message struct {
	Topic string `json:"topic"`
	Key   string `json:"key"`
	Data  string `json:"data"`
}

type TheHub

type TheHub interface {
	Run(ctx context.Context, logger Logger)
	RegisterClient(client ClientInterface)
	UnregisterClient(client ClientInterface)
	BroadcastMessage(message Message)
	HandleWebSocketMessage(message Message)
	UpgradeWebSocket(c *websocket.Conn, logger Logger)
	IsTest(isTest bool)
}

func NewHub

func NewHub(brokers_ []string, logger *log.Logger, config *sarama.Config) TheHub

type WebSocketConnection

type WebSocketConnection struct {
	Conn *websocket.Conn
}

func (*WebSocketConnection) Close

func (wsc *WebSocketConnection) Close() error

func (*WebSocketConnection) ReadMessage

func (wsc *WebSocketConnection) ReadMessage() (int, []byte, error)

func (*WebSocketConnection) WriteMessage

func (wsc *WebSocketConnection) WriteMessage(messageType int, data []byte) error

Jump to

Keyboard shortcuts

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