websocket

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 3 Imported by: 1

README

go-ws-websocket

go-ws-websocket is a package that Websocket clients which are registered a broker broadcast messages.

license

Installation

$ go get -u github.com/gjbae1212/go-ws-websocket

Usage

# create braker
broker, _ :=  NewBreaker()

# register 
client, _ := broker.Register(websocket)

# unregister 
_ = broker.Register(client)

# broadcast message
_ = broker.BroadCast(message)   

LICENSE

This project is following The MIT.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Upgrader = websocket.Upgrader{ReadBufferSize: 1024, WriteBufferSize: 1024}
)

Functions

This section is empty.

Types

type Breaker

type Breaker interface {
	Register(conn *websocket.Conn) (*Client, error)
	UnRegister(client *Client) error
	BroadCast(msg Message) error
	MaxReadLimit() int64
}

func NewBreaker

func NewBreaker(opts ...Option) (Breaker, error)

NewBreaker returns a breaker for websocket.

type Client

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

Client is websocket client.

func NewClient

func NewClient(bk Breaker, conn *websocket.Conn) (*Client, error)

NewClient creates client for websocket.

type ErrorHandler

type ErrorHandler func(error)

type Message

type Message interface {
	GetMessage() []byte
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

type OptionFunc

type OptionFunc func(bk *breaker)

func WithErrorHandlerOption

func WithErrorHandlerOption(f ErrorHandler) OptionFunc

WithErrorHandlerOption returns a function which sets error handler.

func WithMaxMessagePoolLength

func WithMaxMessagePoolLength(length int64) OptionFunc

WithMaxMessagePoolLength returns a function that sets a pool size, which how many data sends with nonblocking.

func WithMaxReadLimit

func WithMaxReadLimit(length int64) OptionFunc

WithMaxReadLimit returns a function which sets max size how many data reads from websocket.

Jump to

Keyboard shortcuts

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