Documentation
ΒΆ
Index ΒΆ
- Variables
- type Client
- func (socket *Client) Close()
- func (socket *Client) GetParserRegistry() *parser.MessageParsers_Registry
- func (socket *Client) SendJSON(v interface{}) error
- func (socket *Client) SendPreparedMessage(preparedMessage *ws.PreparedMessage) error
- func (socket *Client) SendPrivateMessage(message map[string]interface{}, timeout_sec ...int) (response []byte, hasTimedOut bool, err error)
- func (socket *Client) SendText(text string) error
- func (socket *Client) SetHTTPHeader(httpHeader http.Header)
- func (socket *Client) SetURL(URL string)
- type Client_params
- type Connection
- func (connection *Connection) Close()
- func (connection *Connection) GetId() int
- func (connection *Connection) GetParserRegistry() *parser.MessageParsers_Registry
- func (connection *Connection) SendJSON(v interface{}) error
- func (connection *Connection) SendPreparedMessage(message *ws.PreparedMessage) error
- func (connection *Connection) SendText(text string) error
- type ResponseHandler
- type Server
- func (server *Server) Broadcast(v interface{}) (failCount int, err error)
- func (server *Server) ListenAndServe(port int) error
- func (server *Server) ListenAndServeTLS(port int, certificate tls.Certificate) error
- func (server *Server) ListenAndServeTLSWithFiles(port int, certFile, keyFile string) error
- func (server *Server) SetCheckOrigin(checkOrigin func(r *http.Request) bool)
- type Server_Params
Constants ΒΆ
This section is empty.
Variables ΒΆ
var Certificates certificateHandler
Functions ΒΆ
This section is empty.
Types ΒΆ
type Client ΒΆ
type Client struct {
OnMessage func(messageType int, msg []byte)
// Called on any error that originates from the current established connection.
//
// Do not treat this as a disconnection as it can be triggerred multiple times for the same connection and is not a sign of disconnection
//
// Use 'OnDisconnect' instead in that case
OnError func(err error)
// Called once the connection unexpectedly drops, expect to be reconnected shortly after
OnDisconnect func(code int, reason string)
OnReconnectError func(err error)
// Called once a new connection is established after disconnection
OnReconnect func()
// contains filtered or unexported fields
}
func (*Client) GetParserRegistry ΒΆ
func (socket *Client) GetParserRegistry() *parser.MessageParsers_Registry
func (*Client) SendPreparedMessage ΒΆ
func (socket *Client) SendPreparedMessage(preparedMessage *ws.PreparedMessage) error
func (*Client) SendPrivateMessage ΒΆ
func (*Client) SetHTTPHeader ΒΆ
type Client_params ΒΆ
type Client_params struct {
// Default is "id"
PrivateRequestPropertyName string
// contains filtered or unexported fields
}
type Connection ΒΆ
type Connection struct {
Request *http.Request
Data connectionData
OnRequest func(msg []byte, request *ResponseHandler)
OnMessage func(messageType int, msg []byte)
OnError func(err error)
OnClose func(code int, reason string)
// contains filtered or unexported fields
}
func (*Connection) Close ΒΆ
func (connection *Connection) Close()
func (*Connection) GetId ΒΆ
func (connection *Connection) GetId() int
func (*Connection) GetParserRegistry ΒΆ
func (connection *Connection) GetParserRegistry() *parser.MessageParsers_Registry
func (*Connection) SendJSON ΒΆ
func (connection *Connection) SendJSON(v interface{}) error
func (*Connection) SendPreparedMessage ΒΆ
func (connection *Connection) SendPreparedMessage(message *ws.PreparedMessage) error
func (*Connection) SendText ΒΆ
func (connection *Connection) SendText(text string) error
type ResponseHandler ΒΆ
type ResponseHandler struct {
Body []byte
// contains filtered or unexported fields
}
func (*ResponseHandler) Reply ΒΆ
func (request *ResponseHandler) Reply(reply map[string]interface{}) error
func (*ResponseHandler) Unmarshal ΒΆ
func (request *ResponseHandler) Unmarshal(v interface{}) error
type Server ΒΆ
type Server struct {
OnConnect func(*Connection)
OnClose func(connection *Connection, code int, reason string)
Connections struct {
Mu sync.Mutex
Map map[int]*Connection
}
// contains filtered or unexported fields
}
func (*Server) Broadcast ΒΆ
Broadcasts a message to all active connections to the server
'err' is returned only when preparing the message for broadcast goes wrong, meaning no connection was sent the message
Otherwise 'failCount' keeps track of how many connections failed to be sent the message
func (*Server) ListenAndServe ΒΆ
This method WILL block until the server is terminated or an error occurs
func (*Server) ListenAndServeTLS ΒΆ
func (server *Server) ListenAndServeTLS(port int, certificate tls.Certificate) error
This method WILL block until the server is terminated or an error occurs
func (*Server) ListenAndServeTLSWithFiles ΒΆ
This method WILL block until the server is terminated or an error occurs
func (*Server) SetCheckOrigin ΒΆ
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.
type Server_Params ΒΆ
type Server_Params struct {
PrivateMessagePropertyName string
}