talkclient

package
v0.0.0-...-cde1217 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthWithKey

func AuthWithKey(key string) func([]byte) []byte

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 NewClient

func NewClient(options Options) (*Client, error)

NewClient creates a new client object

func (*Client) Connect

func (c *Client) Connect() error

Connect connects the client to a websocket If the client is already connected it will return nil

func (*Client) Disconnect

func (c *Client) Disconnect(err error)

Disconnect disconnects the currnet connection

func (*Client) Send

func (c *Client) Send(title string, data interface{}) error

Send just sends something into the network

func (*Client) SendAndReceive

func (c *Client) SendAndReceive(title string, data interface{}, res interface{}) error

SendAndReceive sends something into the network and waits for a response from someone

func (*Client) Subscribe

func (c *Client) Subscribe(title string, handeler func(msg *WSMessage))

Subscribe can subscibe to a spesific title Example handeler:

func(msg *talkclient.WSMessage)  {
  fmt.Println(string(msg.Bytes))
  return nil
}

func (*Client) SureSend

func (c *Client) SureSend(title string, data interface{}) error

SureSend sends something into the network and wait for some respone on this message If there is no res, it will re-send it Use this when you need to be sure the message will actualy be delivered

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL