Documentation ¶
Index ¶
- type Channel
- func (ch *Channel) AddListener(endpoint string, ...) error
- func (ch *Channel) AddMiddleware(...)
- func (ch *Channel) GetPeer(id uuid.UUID) *peer
- func (ch *Channel) HandlePeer(peer *peer)
- func (ch *Channel) Init()
- func (ch *Channel) ListPeers() []uuid.UUID
- func (ch *Channel) NewPeer(c *websocket.Conn, uri string) *peer
- func (ch *Channel) Send(client uuid.UUID, endpoint string, body []byte) ([]byte, error)
- func (ch *Channel) SetHooks(onConnect *func(id uuid.UUID, uri string, remoteAddr string) error, ...)
- type ChannelOptions
- type Client
- type Conn
- type ErrorCode
- type ProtocolError
- func ApplyReason(fn func(message string, reason *string) ProtocolError, message string, ...) *ProtocolError
- func BadRequest(message string, reason *string) ProtocolError
- func ClientNotConnected(message string, reason *string) ProtocolError
- func InternalError(message string, reason *string) ProtocolError
- func LocalError(message string, reason *string) ProtocolError
- func NotFound(message string, reason *string) ProtocolError
- func Timeout(message string, reason *string) ProtocolError
- type Receiver
- type Server
- func (s *Server) AddListener(endpoint string, ...) error
- func (ch *Server) AddMiddleware(...)
- func (s *Server) IsConnected(client uuid.UUID) bool
- func (s *Server) Listen()
- func (s *Server) Peers() []uuid.UUID
- func (s *Server) Send(client uuid.UUID, endpoint string, body []byte) ([]byte, error)
- func (s *Server) SetHooks(onConnect *func(id uuid.UUID, uri string, remoteAddr string) error, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel abstracts a connection to an either a server or a client
func (*Channel) AddListener ¶
func (*Channel) AddMiddleware ¶
func (*Channel) HandlePeer ¶
func (ch *Channel) HandlePeer(peer *peer)
type ChannelOptions ¶
type ChannelOptions struct { ProtoHandshake time.Duration ProtoWrite time.Duration ProtoRead time.Duration ProtoReconnect time.Duration }
ChannelOptions options for the channel
type Client ¶
Client a protocol client
func NewClient ¶
func NewClient(url url.URL, channelOptions ChannelOptions) *Client
NewClient Creates a new Client addr is the address to connect to channelOptions options, see ChannelOptions docs
func (*Client) AddListener ¶
AddListener adds a listener to the channel for some endpoint
func (*Client) IsConnected ¶
IsConnected checks if a connection to the server is established
func (*Client) Listen ¶
func (c *Client) Listen()
Listen starts connection loop to the server, auto connects when connection fails
type ProtocolError ¶
type ProtocolError struct { Code ErrorCode `json:"code"` Message string `json:"message"` Reason *string `json:"reason"` }
func ApplyReason ¶
func ApplyReason(fn func(message string, reason *string) ProtocolError, message string, err error) *ProtocolError
func BadRequest ¶
func BadRequest(message string, reason *string) ProtocolError
func ClientNotConnected ¶
func ClientNotConnected(message string, reason *string) ProtocolError
func InternalError ¶
func InternalError(message string, reason *string) ProtocolError
func LocalError ¶
func LocalError(message string, reason *string) ProtocolError
func NotFound ¶
func NotFound(message string, reason *string) ProtocolError
func Timeout ¶
func Timeout(message string, reason *string) ProtocolError
func (ProtocolError) Error ¶
func (e ProtocolError) Error() string
type Server ¶
Server a protocol server
func NewServer ¶
func NewServer(addr string, path string, channelOptions ChannelOptions) *Server
NewServer Creates a new Server addr is the address to listen on channelOptions options, see ChannelOptions docs
func (*Server) AddListener ¶
func (s *Server) AddListener(endpoint string, listener func(context.Context, uuid.UUID, []byte) ([]byte, error)) error
AddListener adds a listener to the channel for some endpoint
func (*Server) AddMiddleware ¶
func (*Server) IsConnected ¶
IsConnected checks if the client is connected
func (*Server) Peers ¶
func (s *Server) Peers() []uuid.UUID
Peers returns a list of uuids of the connected clients