websocket

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ReadBufferSizeFieldName        = "server.http.websocket.size.buffer.read"
	WriteBufferSizeFieldName       = "server.http.websocket.size.buffer.write"
	OriginsFieldName               = "server.http.websocket.origins"
	PingTimeoutFieldName           = "server.http.websocket.timeout.ping"
	WriteTimeoutFieldName          = "server.http.websocket.timeout.write"
	ClientEventBufferSizeFieldName = "server.http.websocket.size.buffer.events"

	ReadBufferSizeDefault        = int(1024)
	WriteBufferSizeDefault       = int(1024)
	ClientEventBufferSizeDefault = 10
	WriteTimeoutDefault          = 20 * time.Second
	PingTimeoutDefault           = 60 * time.Second

	AnyOrigin = "*"
)

Variables

View Source
var (
	MessageChanFullError   = errors.New("message channel is full")
	MessageChanClosedError = errors.New("message channel is closed")
)
View Source
var Component = &component.Component{
	Name: "http.server.websocket",
	Init: component.StepFunc(func(container container.Container) error {
		return container.Provides(NewConfig, NewUpgrader)
	}),
	Configuration: component.StepFunc(func(container container.Container) error {
		return container.Invoke(Configuration)
	}),
}

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(conn *websocket.Conn, config *Config, onMessage emitter.Emitter[*Event], logger logger.Logger) *Client

func (*Client) Process

func (c *Client) Process(ctx context.Context) error

func (*Client) Send

func (c *Client) Send(event *Event) error

type Config

type Config struct {
	ReadBufferSize        int
	WriteBufferSize       int
	ClientEventBufferSize int

	WriteTimeout time.Duration
	PingTimeout  time.Duration
	PingInterval time.Duration

	Origins set.Set[string]
	// contains filtered or unexported fields
}

func Configuration

func Configuration(config *Config, configurator configurator.Configurator) *Config

func NewConfig

func NewConfig() *Config

type Event

type Event struct {
	Type      string          `json:"type,omitempty"`
	Payload   json.RawMessage `json:"payload,omitempty"`
	Timestamp *Timestamp      `json:"timestamp,omitempty"`
}

type Handler

type Handler struct {
	OnClientConnection    emitter.Emitter[*Client]
	OnClientDisconnection emitter.Emitter[*Client]
	OnMessage             emitter.Emitter[*Event]
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(
	config *Config,
	upgrader *Upgrader,
	logger logger.Logger,
	closer closer.Closer,
) *Handler

func (*Handler) Send

func (h *Handler) Send(event *Event) (err error)

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type Timestamp

type Timestamp struct {
	Seconds int64 `json:"seconds,omitempty"`
	Nanos   int64 `json:"nanos,omitempty"`
}

type Upgrader

type Upgrader struct {
	*websocket.Upgrader
	// contains filtered or unexported fields
}

func NewUpgrader

func NewUpgrader(config *Config) *Upgrader

func (*Upgrader) CheckOrigin

func (up *Upgrader) CheckOrigin(r *http.Request) bool

Jump to

Keyboard shortcuts

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