go_wss

package module
v0.0.0-...-9e94e2a Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 14 Imported by: 0 modules, 0 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.

Documentation

Index

Constants

View Source
const (
	NotConnected = iota
	Connected
)
View Source
const (
	EventCallback = iota
	EventChannel
)

Variables

View Source
var (
	ErrWssNotConnected = errors.New("wss not connected")

	ErrChannelDuplicateSubscribe = errors.New("cannot subscribe to a same channel twice")

	ErrMessageChannelEmpty = errors.New("empty message channel")
)

Functions

func DumpResponse

func DumpResponse(resp *http.Response, body bool)

func Run

func Run(wssUrl string, header http.Header) (msgChan chan []byte, err error)

func Stop

func Stop()

Types

type WssClient

type WssClient struct {
	sync.Mutex

	SubFunc            func(ch string) string
	UnsubFunc          func(ch string) string
	MsgFunc            func(msg []byte) error
	UncompressedFunc   func(msg []byte) ([]byte, error)
	SystemErrFunc      func(err error)
	AfterConnectedFunc func() error
	// contains filtered or unexported fields
}

func New

func New(opts ...WssClientOpt) *WssClient

func RunNew

func RunNew(opts ...WssClientOpt) (wss *WssClient, msgChan chan []byte, err error)

func (*WssClient) Channel

func (w *WssClient) Channel() (chan []byte, error)

func (*WssClient) Close

func (w *WssClient) Close()

func (*WssClient) Config

func (w *WssClient) Config(opts ...WssClientOpt) *WssClient

func (*WssClient) Conn

func (w *WssClient) Conn() *websocket.Conn

func (*WssClient) Connect

func (w *WssClient) Connect() error

func (*WssClient) ReceiveMsg

func (w *WssClient) ReceiveMsg()

func (*WssClient) Sub

func (w *WssClient) Sub(ch string) error

Sub add a channel to subscribe, Sub is concurrent safe

func (*WssClient) SubAll

func (w *WssClient) SubAll() error

func (*WssClient) Subs

func (w *WssClient) Subs(chs []string)

func (*WssClient) UnSubAll

func (w *WssClient) UnSubAll() error

func (*WssClient) UnSubs

func (w *WssClient) UnSubs()

func (*WssClient) Unsub

func (w *WssClient) Unsub(ch string) error

Unsub add a channel to unsubscribe, Unsub is concurrent safe

func (*WssClient) WriteControl

func (w *WssClient) WriteControl(messageType int, msg []byte, deadline time.Time) error

func (*WssClient) WriteMessage

func (w *WssClient) WriteMessage(messageType int, msg []byte) error

type WssClientOpt

type WssClientOpt func(c *WssClient)

func WithAfterConnectedFunc

func WithAfterConnectedFunc(fn func() error) WssClientOpt

func WithChannel

func WithChannel(channel chan []byte) WssClientOpt

func WithHeader

func WithHeader(header http.Header) WssClientOpt

func WithIsAutoReconnect

func WithIsAutoReconnect(is bool) WssClientOpt

func WithIsDump

func WithIsDump(is bool) WssClientOpt

func WithMessageFunc

func WithMessageFunc(fn func(msg []byte) error) WssClientOpt

func WithReconnectCount

func WithReconnectCount(c int) WssClientOpt

func WithReconnectInterval

func WithReconnectInterval(i time.Duration) WssClientOpt

func WithSubFnc

func WithSubFnc(fn func(string) string) WssClientOpt

func WithSubs

func WithSubs(fn func() []string) WssClientOpt

func WithSystemErrorFunc

func WithSystemErrorFunc(fn func(error)) WssClientOpt

func WithUncompressFunc

func WithUncompressFunc(fn func([]byte) ([]byte, error)) WssClientOpt

func WithUnsubFnc

func WithUnsubFnc(fn func(string) string) WssClientOpt

func WithWsUrl

func WithWsUrl(url string) WssClientOpt

Jump to

Keyboard shortcuts

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