Documentation ¶
Index ¶
- func AuthWithKey(key string) func([]byte) []byte
- type CB
- type Client
- func (c *Client) Connect() error
- func (c *Client) Disconnect(err error)
- func (c *Client) Send(title string, data interface{}) error
- func (c *Client) SendAndReceive(title string, data interface{}, res interface{}) error
- func (c *Client) Subscribe(title string, handeler func(msg *WSMessage))
- func (c *Client) SureSend(title string, data interface{}) error
- type Options
- type SubscribeT
- type WSMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthWithKey ¶
AuthWithKey returns a handeler for Options.Auth If key is empty this function will panic
Types ¶
type CB ¶
type CB struct {
Res interface{} // The response data,
}
CB short for CallBack are the callback options
type Client ¶
type Client struct { ServerURL string ServerWsURL string Connected bool Conn *websocket.Conn DisconnectChan chan error ConnectChan chan struct{} Subscriptions map[string]SubscribeT Auth func([]byte) []byte NoProxy bool Logging bool SendedToChan bool // contains filtered or unexported fields }
Client is the main type from where it's possible to make request
func (*Client) Connect ¶
Connect connects the client to a websocket If the client is already connected it will return nil
func (*Client) Disconnect ¶
Disconnect disconnects the currnet connection
func (*Client) SendAndReceive ¶
SendAndReceive sends something into the network and waits for a response from someone
type Options ¶
type Options struct { Auth func([]byte) []byte // A function to authenticate the message if not spesified this will be ignored ServerURL string // server url, default: http://localhost:8080/ NoProxy bool // Turn off proxy settings Logging bool // If this is true the request will be logged }
Options are options that can be used in the NewClient function
type SubscribeT ¶
type SubscribeT struct { Handeler func(msg *WSMessage) Subscription string // The non-hased subscription }
SubscribeT is the global type for all subscriptions
type WSMessage ¶
type WSMessage struct { Bytes []byte // The actual message ExpectsAnswer bool // ExectsAnswer is true when the sender expects an answer back Aswer func(data interface{}) // Aswer sends a message back to the sender BindJSON func(v interface{}) error // Bind the json data to something, this is the same as json.Unmarshal }
WSMessage is a websocket message
Click to show internal directories.
Click to hide internal directories.