nprotoo

package module
v0.0.0-...-d3337e5 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 11 Imported by: 4 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 RawMessage)

AcceptFunc .

type BroadCastFunc

type BroadCastFunc func(data Notification, 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 interface{})

Say .

type CommonData

type CommonData struct {
	ID     int        `json:"id"`
	Method string     `json:"method"`
	Data   RawMessage `json:"data"`
}

type Error

type Error struct {
	Code   int
	Reason string
}

Error .

func (Error) Error

func (e Error) Error() string

type Future

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

Future .

func NewFuture

func NewFuture() *Future

NewFuture .

func (*Future) Await

func (future *Future) Await() (RawMessage, *Error)

Await .

func (*Future) Then

func (future *Future) Then(resolve func(result RawMessage), 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 {
	CommonData
	NotificationData
}

* Notification

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

type NotificationData

type NotificationData struct {
	Notification bool `json:"notification"`
}

type PeerMsg

func (PeerMsg) ToNotification

func (m PeerMsg) ToNotification() Notification

func (PeerMsg) ToRequest

func (m PeerMsg) ToRequest() Request

type RawMessage

type RawMessage []byte

func (RawMessage) MarshalJSON

func (m RawMessage) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (RawMessage) Unmarshal

func (r RawMessage) Unmarshal(msgType interface{}) *Error

func (*RawMessage) UnmarshalJSON

func (m *RawMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

type RejectFunc

type RejectFunc func(errorCode int, errorReason string)

RejectFunc .

type Request

type Request struct {
	RequestData
	CommonData
}

* Request

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

type RequestData

type RequestData struct {
	Request   bool   `json:"request"`
	ReplySubj string `json:"reply"`
}

type RequestFunc

type RequestFunc func(request Request, accept RespondFunc, 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 interface{}) *Future

AsyncRequest .

func (*Requestor) Request

func (req *Requestor) Request(method string, data 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 interface{}) (RawMessage, *Error)

SyncRequest .

type RespondFunc

type RespondFunc func(data interface{})

type Response

type Response struct {
	ResponseData
	CommonData
}

* Success response

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

func NewResponse

func NewResponse(id int, data interface{}) (*Response, error)

func NewResponseErr

func NewResponseErr(id int, errorCode int, errorReason string) *Response

type ResponseData

type ResponseData struct {
	Response bool `json:"response"`
	Ok       bool `json:"ok"`
	ResponseErrData
}

type ResponseErrData

type ResponseErrData struct {
	ErrorCode   int    `json:"errorCode"`
	ErrorReason string `json:"errorReason"`
}

type ResponseError

type ResponseError struct {
	ResponseData
	CommonData
}

* 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
examples
client command
listener command

Jump to

Keyboard shortcuts

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