connector

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(data interface{})

Callback represents the callback type which will be called when the correspond events is occurred.

type Connector

type Connector struct {
	Options
	// contains filtered or unexported fields
}

Connector is a tiny Nano client

func NewConnector

func NewConnector(opts ...Option) *Connector

NewConnector create a new Connector

func (*Connector) Close

func (c *Connector) Close()

Close closes the connection, and shutdown the benchmark

func (*Connector) Connected

func (c *Connector) Connected() bool

Connected returns the status whether connector is conncected

func (*Connector) Deserialize

func (c *Connector) Deserialize(data []byte, v interface{}) error

Deserialize Unmarshals byte slice into customized data

func (*Connector) GetMid

func (c *Connector) GetMid() uint64

GetMid returns current message id

func (*Connector) Name

func (c *Connector) Name() string

Name returns the name for connector

func (*Connector) Notify

func (c *Connector) Notify(route string, v interface{}) error

Notify send a notification to server

func (*Connector) On

func (c *Connector) On(event string, callback Callback)

On add the callback for the event

func (*Connector) OnConnected

func (c *Connector) OnConnected(callback Callback)

OnConnected set the callback which will be called when the client connected to the server

func (*Connector) OnUnexpectedEvent

func (c *Connector) OnUnexpectedEvent(callback Callback)

OnUnexpectedEvent sets callback for events that are not "On"

func (*Connector) Ready

func (c *Connector) Ready() <-chan struct{}

func (*Connector) Request

func (c *Connector) Request(route string, v interface{}, callback Callback) error

Request send a request to server and register a callbck for the response

func (*Connector) Send added in v1.0.1

func (c *Connector) Send(data []byte)

func (*Connector) Serialize

func (c *Connector) Serialize(v interface{}) ([]byte, error)

Serialize marshals customized data into byte slice

func (*Connector) Start

func (c *Connector) Start(addr string) (err error)

Start connects to the server and send/recv between the c/s

type Option

type Option func(options *Options)

Option used to customize handler

func WithBranch added in v1.0.1

func WithBranch(branch uint32) Option

func WithCodec added in v1.0.1

func WithCodec(codec codec.Codec) Option

WithCodec sets codec instead of default codec

func WithDictionary

func WithDictionary(dictionary message.Dictionary) Option

func WithIsWebSocket added in v1.0.1

func WithIsWebSocket(isWebSocket bool) Option

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger overrides the default logger

func WithName

func WithName(name string) Option

WithName is used to name connector

func WithSerializer

func WithSerializer(serializer serialize.Serializer) Option

WithSerializer customizes application serializer, which automatically Marshal and UnMarshal handler payload

func WithWSPath

func WithWSPath(path string) Option

WithWSPath set the websocket path

type Options

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

Options contains some configurations for connector

Jump to

Keyboard shortcuts

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