gorillapub

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBufferForMessages default buffer size for socket message channel.
	DefaultBufferForMessages = 100

	// DefaultReconnectionWaitCheck defines the default Wait time for checking reconnection.
	DefaultReconnectionWaitCheck = time.Millisecond * 200

	// DefaultWriteWait defines the default Wait time for writing.
	DefaultWriteWait = time.Second * 60

	// DefaultReadWait defines the default Wait time for reading.
	DefaultReadWait = time.Second * 60

	// DefaultPingInterval is the default ping interval for a redelivery
	// of a ping message.
	DefaultPingInterval = (DefaultReadWait * 9) / 10

	// DefaultMessageType defines the default message type expected.
	DefaultMessageType = websocket.BinaryMessage

	// DefaultMaxMessageSize Default maximum message size allowed if user does not set value
	// in SocketConfig.
	DefaultMaxMessageSize = 4096
)
View Source
const EndpointDialTimeout = time.Second * 3

Variables

This section is empty.

Functions

func HttpUpgrader

func HttpUpgrader(
	logger sabuhp.Logger,
	hub *GorillaHub,
	upgrader *websocket.Upgrader,
	custom ResponseHeadersFromRequest,
) http.HandlerFunc

func UpgraderHandler

func UpgraderHandler(
	logger sabuhp.Logger,
	hub *GorillaHub,
	upgrader *websocket.Upgrader,
	custom ResponseHeadersFromRequest,
) sabuhp.Handler

Types

type ConfigCreator

type ConfigCreator func(config SocketConfig) SocketConfig

type DialerEndpoint

type DialerEndpoint struct {
	Addr    string
	Headers http.Header
	Dialer  *websocket.Dialer
}

func DefaultEndpoint

func DefaultEndpoint(addr string, dialTimeout time.Duration) *DialerEndpoint

func (DialerEndpoint) Dial

type Endpoint

type Endpoint interface {
	Dial(ctx context.Context) (*websocket.Conn, *http.Response, error)
}

type GorillaHub

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

func ManagedGorillaHub

func ManagedGorillaHub(
	ctx context.Context,
	logger sabuhp.Logger,
	optionalConfigCreator ConfigCreator,
	codec sabuhp.Codec,
) *GorillaHub

ManagedGorillaHub returns a new instance of a gorilla hub which uses a managers.Manager to manage communication across various websocket connections.

It allows the manager to delegate connections management to a suitable type (i.e GorillaHub) and in the future other protocols/transport while the manager uses the central message bus transport to communicate to other services and back to the connections.

func NewGorillaHub

func NewGorillaHub(config HubConfig) *GorillaHub

func (*GorillaHub) HandleSocket

func (gh *GorillaHub) HandleSocket(socket *websocket.Conn, info *SocketInfo) SocketHandler

HandleSocket implements necessary logic to man and manage the lifecycle of a new socket provided to the hub.

func (*GorillaHub) Start

func (gh *GorillaHub) Start()

func (*GorillaHub) Stats

func (gh *GorillaHub) Stats() ([]sabuhp.SocketStat, error)

func (*GorillaHub) Stop

func (gh *GorillaHub) Stop()

func (*GorillaHub) Stream

func (gh *GorillaHub) Stream(stream sabuhp.SocketService)

func (*GorillaHub) Wait

func (gh *GorillaHub) Wait()

type GorillaSocket

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

func CreateClient added in v0.6.3

func CreateClient(ctx context.Context, logger sabuhp.Logger, codec sabuhp.Codec, addr string, handler sabuhp.SocketMessageHandler) (*GorillaSocket, error)

func GorillaClient

func GorillaClient(config SocketConfig) (*GorillaSocket, error)

func NewGorillaSocket

func NewGorillaSocket(config SocketConfig) *GorillaSocket

func (*GorillaSocket) Conn

func (g *GorillaSocket) Conn() *websocket.Conn

func (*GorillaSocket) ID

func (g *GorillaSocket) ID() nxid.ID

func (*GorillaSocket) Listen

func (g *GorillaSocket) Listen(handler sabuhp.SocketMessageHandler)

func (*GorillaSocket) LocalAddr

func (g *GorillaSocket) LocalAddr() net.Addr

func (*GorillaSocket) RemoteAddr

func (g *GorillaSocket) RemoteAddr() net.Addr

func (*GorillaSocket) Send

func (g *GorillaSocket) Send(messages ...sabuhp.Message)

Send delivers provided message into a batch of messages for delivery.

func (*GorillaSocket) Start

func (g *GorillaSocket) Start()

func (*GorillaSocket) Stat

func (g *GorillaSocket) Stat() sabuhp.SocketStat

func (*GorillaSocket) Stop

func (g *GorillaSocket) Stop()

func (*GorillaSocket) Wait

func (g *GorillaSocket) Wait()

type HubConfig

type HubConfig struct {
	Ctx           context.Context
	Logger        sabuhp.Logger
	Codec         sabuhp.Codec
	ConfigHandler ConfigCreator
}

type ResponseHeadersFromRequest added in v0.4.1

type ResponseHeadersFromRequest func(r *http.Request) http.Header

type SocketConfig

type SocketConfig struct {
	Info                  *SocketInfo
	Buffer                int
	MessageType           int
	MaxMessageSize        int
	WriteMessageWait      time.Duration
	ReadMessageWait       time.Duration
	ReconnectionCheckWait time.Duration
	PingInterval          time.Duration // should be lesser than ReadMessageWait duration
	Ctx                   context.Context
	Logger                sabuhp.Logger
	Codec                 sabuhp.Codec

	// You can supply the websocket.Conn aif you wish to
	// use an existing connection, the endpoint becomes
	// non useful here, and you should set ShouldNotTry to true.
	Conn           *websocket.Conn
	ShouldNotRetry bool

	// Client related fields
	Res      *http.Response // optional
	MaxRetry int
	RetryFn  sabuhp.RetryFunc
	Endpoint Endpoint

	// SocketByteHandler defines the function contract a GorillaSocket uses
	// to handle a message.
	//
	// Be aware that returning an error from the handler to the Gorilla Socket
	// will cause the immediate closure of that socket and ending communication
	// with the server. So unless your intention is to
	// end the connection, handle the error yourself.
	Handler sabuhp.SocketMessageHandler
}

type SocketHandler

type SocketHandler interface {
	Run() error
}

type SocketInfo

type SocketInfo struct {
	Query   url.Values
	Path    string
	Headers sabuhp.Header
}

Jump to

Keyboard shortcuts

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