Documentation ¶
Overview ¶
Pine's websocket package is a websocket server that supports multiple channels This feature is experimental and may change in the future. Please use it with caution and at your own risk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
Called to open a new connection and upgrade it to a websocket connection this is the main function to use to create a new websocket connection Use this function if the Type is set to "self"
func WatchFile ¶
This is an experimental feature and may change in the future WatchFile is used to watch a file for changes and send the changes to the client This is particularly useful for live streaming of files
If you notice performance issues as you try to stream files please use a different method to stream files WatchFile is not recommended for streaming large files
WatchFile automatically handles file changes but may not be suited for fast changes and may lead to performance issues TODO: Improve performance and add support for fast changes
Types ¶
type Config ¶
type Config struct {
// ReadBufferSize and WriteBufferSize specify I/O buffer sizes in bytes. If a buffer
// size is zero, then buffers allocated by the HTTP server are used. The
// I/O buffer sizes do not limit the size of the messages that can be sent
// or received.
ReadBufferSize, WriteBufferSize int
// Subprotocols specifies the server's supported protocols in order of
// preference. If this field is not nil, then the Upgrade method negotiates a
// subprotocol by selecting the first match in this list with a protocol
// requested by the client. If there's no match, then no protocol is
// negotiated (the Sec-Websocket-Protocol header is not included in the
// handshake response).
SubprotocolsAllowed []string
// CheckOrigin returns true if the request Origin header is acceptable. If
// CheckOrigin is nil, then a safe default is used: return false if the
// Origin request header is present and the origin host is not equal to
// request Host header.
//
// A CheckOrigin function should carefully validate the request origin to
// prevent cross-site request forgery.
CheckOrigin func(r *http.Request) bool
// Error specifies the function for generating HTTP error responses. If Error
// is nil, then http.Error is used to generate the HTTP response.
Error func(w http.ResponseWriter, r *http.Request, status int, reason error)
// EnableCompression specify if the server should attempt to negotiate per
// message compression (RFC 7692). Setting this value to true does not
// guarantee that compression will be supported. Currently only "no context
// takeover" modes are supported.
EnableCompression bool
// HandshakeTimeout specifies the duration for the handshake to complete.
HandshakeTimeout time.Duration
}
Config is a struct that holds the configuration for the websocket server