Documentation
¶
Index ¶
- Variables
- func LogErrors()
- func MsgType[T goutil.SupportedType](msg interface{}) interface{}deprecated
- func ToType[T goutil.SupportedType](msg interface{}) T
- type Client
- type Server
- func (s *Server) Broadcast(name string, msg interface{})
- func (s *Server) Connect(cb func(client *Client))
- func (s *Server) Disconnect(cb func(client *Client, code int))
- func (s *Server) Handler() websocket.Handler
- func (s *Server) Kick(clientID string, code int)
- func (s *Server) KickAll(code int)
- func (s *Server) On(name string, cb func(client *Client, msg interface{}))
- func (s *Server) Send(clientID string, name string, msg interface{})
Constants ¶
This section is empty.
Variables ¶
var ErrLog []error = []error{}
ErrLog contains a list of client errors which you can handle any way you would like
var GzipEnabled = true
GzipEnabled defines whether or not gzip compression is enabled be default for new websocket servers
Deprecated: please use `Server.Gzip` instead
Functions ¶
func LogErrors ¶
func LogErrors()
LogErrors can be used if you would like client errors to be logged with fmt.Println
By default, these errors will not be logged
func MsgType
deprecated
func MsgType[T goutil.SupportedType](msg interface{}) interface{}
MsgType attempts to converts any interface{} from the many possible json outputs, to a specific type of your choice
if it fails to convert, it will return a nil/zero value for the appropriate type
recommended: add .(string|[]byte|int|etc) to the end of the function to get that type output in place of interface{}
Deprecated: Please use 'websocket.ToType' instead
func ToType ¶ added in v1.3.0
func ToType[T goutil.SupportedType](msg interface{}) T
ToType attempts to converts any interface{} from the many possible json outputs, to a specific type of your choice
if it fails to convert, it will return a nil/zero value for the appropriate type
Unlike 'websocket.MsgType' This method now returns the actual type, in place of returning an interface{} with that type
Types ¶
type Client ¶
type Client struct { ClientID string Store map[string]interface{} // contains filtered or unexported fields }
Client of a websocket
func (*Client) Disconnect ¶
Disconnect runs your callback when the client disconnects from the websocket
type Server ¶
type Server struct { // ReqSize defines number of kilobytes (KB) that can be sent by a client at a time // // default: 1024 (1MB) ReqSize uint32 // Gzip defines whether or not gzip compression is enabled for the websocket server Gzip bool // contains filtered or unexported fields }
Server for a websocket
func NewServer ¶
NewServer creates a new server
@origin enforces a specific http/https host to be accepted, and rejects connections from other hosts
func (*Server) Disconnect ¶
Disconnect runs your callback when any client disconnects from the websocket
func (*Server) Handler ¶
Handler should be passed into your http handler
http.Handle("/ws", server.Handler())