wshub

package
v0.0.0-...-b226945 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: BSD-2-Clause Imports: 12 Imported by: 2

Documentation

Overview

Package wshub provides a websocket server and client using gorilla/websocket for package hub.

Index

Constants

This section is empty.

Variables

View Source
var AsBinary msgKind = websocket.BinaryMessage

Functions

func WSURL

func WSURL(url string) string

WSURL returns url with a http or https prefix replaced as ws or wss respectively.

Types

type Backoff

type Backoff func(retry int, err error) (time.Duration, error)

Backoff returns a duration to sleep before reconnecting or an error.

type Client

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

Client is connection to a hub served over websockets.

func NewClient

func NewClient(ctx context.Context, conf Config) *Client

NewClient returns a new client with the given configuration.

func (*Client) Chan

func (c *Client) Chan() chan<- *hub.Msg

func (*Client) Ctx

func (c *Client) Ctx() context.Context

func (*Client) ID

func (c *Client) ID() int64

func (*Client) Run

func (c *Client) Run(r chan<- *hub.Msg) error

Run connects the client and blocks while sending incoming messages to r and returns an error.

func (*Client) RunWithBackoff

func (c *Client) RunWithBackoff(r chan<- *hub.Msg, bof Backoff) error

RunWithBackoff blocks while running and reconnecting using a backoff function.

func (*Client) Start

func (c *Client) Start(r chan<- *hub.Msg) error

Start connects the client and continues sending incoming messages to r or returns an error.

func (*Client) User

func (c *Client) User() string

type Config

type Config struct {
	URL  string
	User string
	*websocket.Dialer
	TokenProvider
	Log log.Logger
}

func (Config) Default

func (c Config) Default() Config

type Server

type Server struct {
	*hub.Hub
	websocket.Upgrader
	Timeout  time.Duration
	UserFunc func(*http.Request) (string, error)
	Log      log.Logger
}

func NewServer

func NewServer(h *hub.Hub) *Server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TokenProvider

type TokenProvider interface {
	Token(url string) (http.Header, error)
	ClearToken(url string) error
}

Jump to

Keyboard shortcuts

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