Documentation ¶
Index ¶
Constants ¶
const ( WSConnClosed int32 = iota WSConnOpen WSConnClosing )
const (
ReceiveChSize = 5000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(cfg ClientConfig, opts ...ClientOption) (*Client, error)
NewClient initializes and returns a new WebSocket client.
func (*Client) ErrorCh ¶
ErrorCh returns a channel that is used to receive client errors asynchronously.
func (*Client) GetConnState ¶ added in v0.15.0
type ClientAuthType ¶ added in v0.13.0
type ClientAuthType int
const ( BasicClientAuthType ClientAuthType = iota + 1 BearerClientAuthType )
type ClientConfig ¶
type ClientConfig struct { // URL specifies the WebSocket URL to connect to. // Should start with either `ws://` or `wss://`. URL string // ConnID specifies the id of the connection to be used in case of // reconnection. Should be left empty on initial connect. ConnID string // AuthToken specifies the token to be used to authenticate // the connection. AuthToken string // AuthType specifies the type of HTTP authentication to use when connecting. AuthType ClientAuthType }
func (ClientConfig) IsValid ¶
func (c ClientConfig) IsValid() error
type ClientOption ¶
func WithDialFunc ¶ added in v0.5.0
func WithDialFunc(dialFn DialContextFn) ClientOption
WithDialFunc lets the caller set an optional dialing function to setup the TCP connection needed by the client.
func WithLogger ¶ added in v0.16.0
func WithLogger(log *slog.Logger) ClientOption
WithLogger lets the caller set an optional logger.
type DialContextFn ¶ added in v0.5.0
type Message ¶
type Message struct { ClientID string ConnID string Type MessageType Data []byte }
Message defines the data to be sent to or received from a ws connection.
type MessageType ¶
type MessageType int
MessageType defines the type of message sent to or received from a ws connection.
const ( TextMessage MessageType = iota + 1 BinaryMessage OpenMessage CloseMessage )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(cfg ServerConfig, log mlog.LoggerIFace, opts ...ServerOption) (*Server, error)
NewServer initializes and returns a new WebSocket server.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the websocket server and closes all the ws connections. Must be called once all senders are done.
func (*Server) ReceiveCh ¶
ReceiveCh returns a channel that can be used to receive messages from ws connections.
type ServerConfig ¶
type ServerConfig struct { // ReadBufferSize specifies the size of the internal buffer // used to read from a ws connection. ReadBufferSize int // WriteBufferSize specifies the size of the internal buffer // used to wirte to a ws connection. WriteBufferSize int // PingInterval specifies the interval at which the server should send ping // messages to its connections. If the client doesn't respond in 2*PingInterval // the server will consider the client as disconnected and drop the connection. PingInterval time.Duration }
func (ServerConfig) IsValid ¶
func (c ServerConfig) IsValid() error
type ServerOption ¶
func WithAuthCb ¶
func WithAuthCb(cb AuthCb) ServerOption
WithAuthCb lets the caller set an optional callback to be called prior to performing the WebSocket upgrade.