ws

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

websocket handler built on top of guerilla/websocket

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a middleman between the websocket connection and the hub.

type DefaultDialer

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

func NewDialer

func NewDialer(addr string) *DefaultDialer

func (*DefaultDialer) Addr

func (dialer *DefaultDialer) Addr() string

func (*DefaultDialer) Send

func (dialer *DefaultDialer) Send(data any) error

Send message to all websocket clients

type HubOption

type HubOption func(*WebsocketHandler)

func OnMessage

func OnMessage(f func(msg []byte)) HubOption

type WebsocketHandler

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

WebsocketHandler maintains the set of active clients and broadcasts messages to the clients.

WebsocketHandler implements http.Handler interface and can be used directly in your http routes.

hub, quit := ws.NewHandler()
defer quit()

go hub.Run()
http.Handle("/", http.FileServer(http.Dir("public")))
http.Handle("/ws", hub)
log.Fatal(http.ListenAndServe(":8080", nil))

func NewHandler

func NewHandler(options ...HubOption) (handler *WebsocketHandler, quit func())

func (*WebsocketHandler) Run

func (h *WebsocketHandler) Run()

Infinite loop that runs the hub indefinately. Run this is a go routine.

func (*WebsocketHandler) ServeHTTP

func (hub *WebsocketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http handler

Jump to

Keyboard shortcuts

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