reconnect

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: MIT Imports: 7 Imported by: 0

README

WS Reconnect

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotDialed     = errors.New("method 'Dial' wasn't called")
	ErrAlreadyDialed = errors.New("method 'Dial' was already called")

	ErrNotConnected = errors.New("not connected")

	// ErrDial is used when 'websocket.Dial' returns an error
	ErrDial = errors.New("dial error")
	// ErrSubscribe is used when subscribe handler returns an error
	ErrSubscribe = errors.New("subscribe error")
	// ErrReconnect is used when reconnection wasn't successful
	ErrReconnect = errors.New("reconnect error")
)

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Debug(msg string)
	Info(msg string)
	Error(msg string)
}

type NoopLogger

type NoopLogger struct{}

func (NoopLogger) Debug

func (NoopLogger) Debug(msg string)

func (NoopLogger) Error

func (NoopLogger) Error(msg string)

func (NoopLogger) Info

func (NoopLogger) Info(msg string)

type ReConn

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

func New

func New() *ReConn

New creates a new instance of 'ReConn'. To set url, timeouts and etc. use methods 'Set...'

func (*ReConn) Close

func (r *ReConn) Close() error

Close closes connection

func (*ReConn) Dial

func (r *ReConn) Dial() error

func (*ReConn) GetDialBody

func (r *ReConn) GetDialBody() []byte

func (*ReConn) ReadMessage

func (r *ReConn) ReadMessage() (messageType int, data []byte, readErr error)

func (*ReConn) SetHandshakeTimeout

func (r *ReConn) SetHandshakeTimeout(d time.Duration) *ReConn

SetHandshakeTimeout sets handshake timeout. After 'Dial' call it does nothing

func (*ReConn) SetLogger

func (r *ReConn) SetLogger(log Logger) *ReConn

SetLogger sets logger. After 'Dial' call it does nothing

func (*ReConn) SetReconnectTimeout

func (r *ReConn) SetReconnectTimeout(d time.Duration) *ReConn

SetReconnectTimeout sets reconnect timeout. After 'Dial' call it does nothing

func (*ReConn) SetSubscribeHandler

func (r *ReConn) SetSubscribeHandler(f SubscribeHandler) *ReConn

SetSubscribeHandler sets subscribe handler. After 'Dial' call it does nothing

func (*ReConn) SetURL

func (r *ReConn) SetURL(url string) *ReConn

SetURL sets url. After 'Dial' call it does nothing

func (*ReConn) WriteMessage

func (r *ReConn) WriteMessage(messageType int, data []byte) error

type SubscribeHandler

type SubscribeHandler func(WsConnection) error

type WsConnection

type WsConnection interface {
	ReadMessage() (messageType int, p []byte, err error)
	WriteMessage(messageType int, data []byte) error
	Close() error
}

Jump to

Keyboard shortcuts

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