nprotoo

package module
v0.0.0-...-1d584fa Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: MIT Imports: 11 Imported by: 0

README

nats-protoo

A golang signaling framework based on NATS MQ.

Documentation

Index

Constants

View Source
const (
	DefaultNatsURL = "nats://127.0.0.1:4222"
)
View Source
const (
	// DefaultRequestTimeout .
	DefaultRequestTimeout = 15 * time.Second
)

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes .

func GenerateRandomNumber

func GenerateRandomNumber() int

GenerateRandomNumber .

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString .

func RandInt

func RandInt(min, max int) int

RandInt .

Types

type AcceptFunc

type AcceptFunc func(data map[string]interface{})

AcceptFunc .

type BroadCastFunc

type BroadCastFunc func(data map[string]interface{}, subj string)

BroadCastFunc .

type Broadcaster

type Broadcaster struct {
	emission.Emitter
	// contains filtered or unexported fields
}

Broadcaster .

func (*Broadcaster) Say

func (bc *Broadcaster) Say(method string, data map[string]interface{})

Say .

type Error

type Error struct {
	Code   int
	Reason string
}

Error .

type Future

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

Future .

func NewFuture

func NewFuture() *Future

NewFuture .

func (*Future) Await

func (future *Future) Await() (map[string]interface{}, *Error)

Await .

func (*Future) Then

func (future *Future) Then(resolve func(result map[string]interface{}), reject func(err *Error))

Then .

type NatsProtoo

type NatsProtoo struct {
	emission.Emitter
	// contains filtered or unexported fields
}

NatsProtoo .

func NewNatsProtoo

func NewNatsProtoo(server string) *NatsProtoo

NewNatsProtoo .

func (*NatsProtoo) Close

func (np *NatsProtoo) Close()

Close .

func (*NatsProtoo) NewBroadcaster

func (np *NatsProtoo) NewBroadcaster(channel string) *Broadcaster

func (*NatsProtoo) NewRequestor

func (np *NatsProtoo) NewRequestor(channel string) *Requestor

func (*NatsProtoo) OnBroadcast

func (np *NatsProtoo) OnBroadcast(channel string, listener BroadCastFunc)

func (*NatsProtoo) OnRequest

func (np *NatsProtoo) OnRequest(channel string, listener RequestFunc)

func (*NatsProtoo) Reply

func (np *NatsProtoo) Reply(message []byte, reply string) error

Reply .

func (*NatsProtoo) Send

func (np *NatsProtoo) Send(message []byte, subj string, reply string) error

Send .

type Notification

type Notification struct {
	Notification bool                   `json:"notification"`
	Method       string                 `json:"method"`
	Data         map[string]interface{} `json:"data"`
}

* Notification

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

type RejectFunc

type RejectFunc func(errorCode int, errorReason string)

RejectFunc .

type Request

type Request struct {
	Request   bool                   `json:"request"`
	ID        int                    `json:"id"`
	ReplySubj string                 `json:"reply"`
	Method    string                 `json:"method"`
	Data      map[string]interface{} `json:"data"`
}

* Request

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

type RequestFunc

type RequestFunc func(request map[string]interface{}, accept AcceptFunc, reject RejectFunc)

RequestFunc .

type Requestor

type Requestor struct {
	emission.Emitter
	// contains filtered or unexported fields
}

Requestor .

func (*Requestor) AsyncRequest

func (req *Requestor) AsyncRequest(method string, data map[string]interface{}) *Future

AsyncRequest .

func (*Requestor) Request

func (req *Requestor) Request(method string, data map[string]interface{}, success AcceptFunc, reject RejectFunc)

Request .

func (*Requestor) SetRequestTimeout

func (req *Requestor) SetRequestTimeout(d time.Duration)

SetRequestTimeout .

func (*Requestor) SyncRequest

func (req *Requestor) SyncRequest(method string, data map[string]interface{}) (map[string]interface{}, *Error)

SyncRequest .

type Response

type Response struct {
	Response bool                   `json:"response"`
	ID       int                    `json:"id"`
	Ok       bool                   `json:"ok"`
	Data     map[string]interface{} `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 Transcation

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

Transcation .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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