Documentation
¶
Index ¶
- Constants
- func HttpUpgrader(logger sabuhp.Logger, hub *GorillaHub, upgrader *websocket.Upgrader, ...) http.HandlerFunc
- func UpgraderHandler(logger sabuhp.Logger, hub *GorillaHub, upgrader *websocket.Upgrader, ...) sabuhp.Handler
- type ConfigCreator
- type CustomHeader
- type DialerEndpoint
- type Endpoint
- type GorillaHub
- type GorillaSocket
- func (g *GorillaSocket) Conn() *websocket.Conn
- func (g *GorillaSocket) ID() nxid.ID
- func (g *GorillaSocket) LocalAddr() net.Addr
- func (g *GorillaSocket) RemoteAddr() net.Addr
- func (g *GorillaSocket) Send(message []byte, meta sabuhp.MessageMeta, timeout time.Duration) error
- func (g *GorillaSocket) SendMessage(message *sabuhp.Message, timeout time.Duration) error
- func (g *GorillaSocket) SendWriter(message io.WriterTo, meta sabuhp.MessageMeta, timeout time.Duration) sabuhp.ErrorWaiter
- func (g *GorillaSocket) Start()
- func (g *GorillaSocket) Stat() sabuhp.SocketStat
- func (g *GorillaSocket) Stop()
- func (g *GorillaSocket) Wait()
- type HubConfig
- type SocketConfig
- type SocketHandler
- type SocketInfo
Constants ¶
const ( // default buffer size for socket message channel. DefaultBufferForMessages = 100 // DefaultReconnectionWaitCheck defines the default Wait time for checking reconnection. DefaultReconnectionWaitCheck = time.Millisecond * 200 // DefaultReadWait 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 // Default maximum message size allowed if user does not set value // in SocketConfig. DefaultMaxMessageSize = 4096 )
Variables ¶
This section is empty.
Functions ¶
func HttpUpgrader ¶
func HttpUpgrader( logger sabuhp.Logger, hub *GorillaHub, upgrader *websocket.Upgrader, custom CustomHeader, ) http.HandlerFunc
func UpgraderHandler ¶
func UpgraderHandler( logger sabuhp.Logger, hub *GorillaHub, upgrader *websocket.Upgrader, custom CustomHeader, ) sabuhp.Handler
Types ¶
type ConfigCreator ¶
type ConfigCreator func(config SocketConfig) SocketConfig
type DialerEndpoint ¶
func DefaultEndpoint ¶
func DefaultEndpoint(addr string, dialTimeout time.Duration) *DialerEndpoint
type GorillaHub ¶
type GorillaHub struct {
// contains filtered or unexported fields
}
func ManagedGorillaHub ¶
func ManagedGorillaHub( logger sabuhp.Logger, manager *managers.Manager, 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) Wait ¶
func (gh *GorillaHub) Wait()
type GorillaSocket ¶
type GorillaSocket struct {
// contains filtered or unexported fields
}
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) LocalAddr ¶
func (g *GorillaSocket) LocalAddr() net.Addr
func (*GorillaSocket) RemoteAddr ¶
func (g *GorillaSocket) RemoteAddr() net.Addr
func (*GorillaSocket) Send ¶
func (g *GorillaSocket) Send(message []byte, meta sabuhp.MessageMeta, timeout time.Duration) error
Send delivers provided message into a batch of messages for delivery.
Send provides no guarantee that your message will immediately be delivered but while a connection remains open it guarantees such a message will remain.
func (*GorillaSocket) SendMessage ¶ added in v0.1.4
SendMessage delivers provided message into a batch of messages for delivery.
Send provides no guarantee that your message will immediately be delivered but while a connection remains open it guarantees such a message will remain.
func (*GorillaSocket) SendWriter ¶
func (g *GorillaSocket) SendWriter(message io.WriterTo, meta sabuhp.MessageMeta, timeout time.Duration) sabuhp.ErrorWaiter
SendWriter delivers provided message into a batch of messages for delivery.
SendWriter provides no guarantee that your message will immediately be delivered but while a connection remains open it guarantees such a message will remain.
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 Handler sabuhp.SocketHandler OnClosure managers.SocketNotification OnOpen managers.SocketNotification Codec sabuhp.Codec ConfigHandler ConfigCreator }
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 // MessageHandler 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.SocketHandler }
type SocketHandler ¶
type SocketHandler interface {
Run() error
}