Categorygithub.com/relaytools/go-wsstat
modulepackage
0.0.0-20240624222222-831694dc7443
Repository: https://github.com/relaytools/go-wsstat.git
Documentation: pkg.go.dev

# README

go-wsstat Go Documentation MIT License

Use the go-wsstat Golang package to trace WebSocket connection and latency in your Go applications. It wraps the gorilla/websocket package for the WebSocket protocol implementation, and measures the duration of the different phases of the connection cycle. The program takes inspiration from the go-httpstat package, which is useful for tracing HTTP requests.

Install

The package is built on Go 1.21 but it has been tested to work with Go 1.18, in case that is of interest. Install to use in your project with go get:

go get github.com/jakobilobi/go-wsstat

Usage

The _example/main.go program demonstrates how to use the go-wsstat package to trace a WebSocket connection.

Run the example:

go run _example/main.go <a WebSocket URL>

Run the tests:

make test

# Functions

MeasureLatency establishes a WebSocket connection, sends a message, reads the response, and closes the connection.
MeasureLatencyJSON establishes a WebSocket connection, sends a JSON message, reads the response, and closes the connection.
MeasureLatencyPing establishes a WebSocket connection, sends a ping message, awaits the pong response, and closes the connection.
NewWSStat creates and returns a new WSStat instance.
Port returns the port number from a URL.
SetCustomTLSConfig allows users to provide their own TLS configuration.
SetDialTimeout sets the dial timeout for WSStat.
SetLogger sets the logger for WSStat.
SetLogLevel sets the log level for WSStat.

# Structs

CertificateDetails holds details regarding a certificate.
Result holds durations of each phase of a WebSocket connection, cumulative durations over the connection timeline, and other relevant connection details.
WSStat wraps the gorilla/websocket package and includes latency measurements in Result.