peer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomNumber

func GenerateRandomNumber() int

func RandInt

func RandInt(min, max int) int

Types

type AcceptFunc

type AcceptFunc func(data json.RawMessage)

type Notification

type Notification struct {
	Notification bool            `json:"notification"`
	Method       string          `json:"method"`
	Data         json.RawMessage `json:"data"`
}

* Notification

{
  notification : true,
  method       : 'chatmessage',
  data         :
  {
    foo : 'bar'
  }
}

type Peer

type Peer struct {
	PeerChans
	// contains filtered or unexported fields
}

func NewPeer

func NewPeer(id string, con *transport.WebSocketTransport) *Peer

func (*Peer) Close

func (peer *Peer) Close()

func (*Peer) ID

func (peer *Peer) ID() string

func (*Peer) Notify

func (peer *Peer) Notify(method string, data interface{})

func (*Peer) Request

func (peer *Peer) Request(method string, data interface{}, success AcceptFunc, reject RejectFunc) chan ResultFuture

func (*Peer) Run

func (peer *Peer) Run()

type PeerChans

type PeerChans struct {
	OnRequest      chan RequestData
	SendRequest    chan SendRequestData
	OnNotification chan Notification
	OnClose        chan transport.TransportErr
	OnError        chan transport.TransportErr
}

type PeerErr

type PeerErr transport.TransportErr

type PeerMsg

type PeerMsg struct {
	Request      bool `json:"request"`
	Response     bool `json:"response"`
	Ok           bool `json:"ok"`
	Notification bool `json:"notification"`
}

type RejectFunc

type RejectFunc func(errorCode int, errorReason string)

type Request

type Request struct {
	Request bool            `json:"request"`
	Id      int             `json:"id"`
	Method  string          `json:"method"`
	Data    json.RawMessage `json:"data"`
}

* Request

{
  request : true,
  id      : 12345678,
  method  : 'chatmessage',
  data    :
  {
    type  : 'text',
    value : 'Hi there!'
  }
}

type RequestData

type RequestData struct {
	Accept  RespondFunc
	Reject  RejectFunc
	Request Request
}

type RespondFunc

type RespondFunc func(data interface{})

type Response

type Response struct {
	Response bool            `json:"response"`
	Id       int             `json:"id"`
	Ok       bool            `json:"ok"`
	Data     json.RawMessage `json:"data"`
}

* Success response

{
	response : true,
	id       : 12345678,
	ok       : true,
	data     :
	{
	  foo : 'lalala'
	}
}

type ResponseError

type ResponseError struct {
	Response    bool   `json:"response"`
	Id          int    `json:"id"`
	Ok          bool   `json:"ok"`
	ErrorCode   int    `json:"errorCode"`
	ErrorReason string `json:"errorReason"`
}

* Error response

{
  response    : true,
  id          : 12345678,
  ok          : false,
  errorCode   : 123,
  errorReason : 'Something failed'
}

type ResultFuture

type ResultFuture struct {
	Result json.RawMessage
	Err    *PeerErr
}

type SendRequestData

type SendRequestData struct {
	*Request
	*Transcation
}

type Transcation

type Transcation struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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