Skip to content
wsc is a library that allows to interact with web sockets using channels.
Go Makefile
Branch: master
Clone or download
Latest commit 28d661b Sep 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE new: licensing May 1, 2019
Makefile remove gopkg Sep 13, 2019
README.md fixed: update readme May 1, 2019
config.go new: licensing May 1, 2019
doc.go new: licensing May 1, 2019
go.mod random new dependencies... Jun 28, 2019
go.sum random new dependencies... Jun 28, 2019
interface.go new: licensing May 1, 2019
mock.go new: licensing May 1, 2019
mock_test.go new: licensing May 1, 2019
wsc.go fixed: increase size of chan to avoid printing error message May 21, 2019
wsc_test.go new: licensing May 1, 2019

README.md

WSC

codecov

WSC (WebSocket Channel) is a library that can be used to manage github.com/gorilla/websocket using channels.

It provides 2 main functions:

  • func Connect(ctx context.Context, url string, config Config) (Websocket, *http.Response, error)
  • func Accept(ctx context.Context, conn WSConnection, config Config) (Websocket, error)

The interface WSConnection is used to interract with the websocket:

// Websocket is the interface of channel based websocket.
type Websocket interface {

  // Reads returns a channel where the incoming messages are published.
  // If nothing pumps the Read() while it is full, new messages will be
  // discarded.
  //
  // You can configure the size of the read chan in Config.
  // The default is 64 messages.
  Read() chan []byte

  // Write writes the given []byte in to the websocket.
  // If the other side of the websocket cannot get all messages
  // while the internal write channel is full, new messages will
  // be discarded.
  //
  // You can configure the size of the write chan in Config.
  // The default is 64 messages.
  Write([]byte)

  // Done returns a channel that will return when the connection
  // is closed.
  //
  // The content will be nil for clean disconnection or
  // the error that caused the disconnection. If nothing pumps the
  // Done() channel, the error will be discarded.
  Done() chan error

  // Close closes the websocket.
  //
  // Closing the websocket a second time has no effect.
  // A closed Websocket cannot be reused.
  Close(code int)

  // Error returns a channel that will return errors like
  // read or write discards and other errors that are not
  // terminating the connection.
  //
  // If nothing pumps the Error() channel, the error will be discarded.
  Error() chan error
}
You can’t perform that action at this time.