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
}