Documentation ¶
Index ¶
- Variables
- type Cfg
- type Client
- func (c *Client) Broadcast(msg *message.Message) (payloadSize int, err error)
- func (c *Client) Close(ctx context.Context) (err error)
- func (c *Client) ConnSlot() *conn.Slot
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) Handle(msg proto.Message, h message.Handler)
- func (c *Client) Middleware(m message.Middleware)
- func (c *Client) Publish(topic string, msg *message.Message) (payloadSize int, err error)
- func (c *Client) RegisterMessage(msg proto.Message)
- func (c *Client) Send(msg *message.Message) (payloadSize int, err error)
- func (c *Client) SendSync(ctx context.Context, msg *message.Message) (payloadSize int, response *message.Message, err error)
- func (c *Client) Subscribe(topic string) (err error)
- func (c *Client) Unsubscribe(topic string) (err error)
- type MeteredClient
- func (c *MeteredClient) Broadcast(msg *message.Message) error
- func (c *MeteredClient) Close(ctx context.Context) (err error)
- func (c *MeteredClient) Connect(ctx context.Context) error
- func (c *MeteredClient) Handle(msg proto.Message, h message.Handler)
- func (c *MeteredClient) Middleware(m message.Middleware)
- func (c *MeteredClient) Publish(topic string, msg *message.Message) error
- func (c *MeteredClient) RegisterMessage(msg proto.Message)
- func (c *MeteredClient) Send(msg *message.Message) (payloadSize int, err error)
- func (c *MeteredClient) SendSync(ctx context.Context, msg *message.Message) (payloadSize int, response *message.Message, err error)
- func (c *MeteredClient) Subscribe(topic string) error
- func (c *MeteredClient) Unsubscribe(topic string) error
- type Option
- func WithCompressionEnabled(b bool) Option
- func WithHandShakeTimeout(d time.Duration) Option
- func WithHeartbeatInterval(interval time.Duration) Option
- func WithMaxConcurrency(n int) Option
- func WithOnCloseHook(h func()) Option
- func WithOnConfiguration(h func(cfg *Cfg)) Option
- func WithOnErrorHook(h func(err error)) Option
- func WithOnStatusChangeHook(h func(status uint32)) Option
- func WithOnWorkerEnd(h func()) Option
- func WithOnWorkerStart(h func()) Option
- func WithReadBufferSize(s int) Option
- func WithServerAddr(addr string) Option
- func WithTLSConfig(tlsCfg *tls.Config) Option
- func WithWriteBufferSize(s int) Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotRunning = errors.New("not running") ErrAlreadyRunning = errors.New("already running") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds are the client subsystems and dependencies.
func (*Client) Close ¶
Close will initiate the graceful shutdown procedure for this client. It will work in a best effort way. In case of errors, they are going to be collected and returned as a multi-error type, with the hope the maximum number of closing actions are performed.
func (*Client) Connect ¶
Connect tries a connection to the specified server. This method can be called after a client shutdown again in order to retry the connection.
func (*Client) Handle ¶
Handle registers a message handler in the client. It will panic if the client its already running.
func (*Client) Middleware ¶
func (c *Client) Middleware(m message.Middleware)
Middleware registers a middleware in the client. It will panic if the client its already running.
func (*Client) RegisterMessage ¶
RegisterMessage will make the client aware of a specific kind of protocol buffer message. This is specially needed when the user sends messages with methods like SendSync(), as the client needs to know how to decode the incoming reply.
If the kind of message it's already registered with the Handle() method, then the user can omit this registration.
Any kind of protocol buffers message that arrives to the client, and It's not registered, will be discarded.
func (*Client) Send ¶
Send will write the provided *message.Message to the output buffer. This method is completely asynchronous. In case the client has closed the connection due to other reasons, ErrNotRunning will be returned.
If successful, it will return the payload size in bytes. This payload size does not include the goomerang base message (which is around 12 bytes) nor the headers.
func (*Client) SendSync ¶
func (c *Client) SendSync(ctx context.Context, msg *message.Message) (payloadSize int, response *message.Message, err error)
SendSync will send a message to the server and wait for a reply. If the provided context is canceled, this function will return immediately and the reply message will be lost.
If successful, it will return the payload size in bytes. This payload size does not include the goomerang base message (which is around 12 bytes) nor the headers.
ErrNotRunning error will be returned in case the client was closed for any reason.
func (*Client) Unsubscribe ¶ added in v0.2.0
type MeteredClient ¶
type MeteredClient struct {
// contains filtered or unexported fields
}
func NewMetered ¶
func NewMetered(m *metrics.ClientMetrics, opts ...Option) (*MeteredClient, error)
func (*MeteredClient) Broadcast ¶ added in v0.2.0
func (c *MeteredClient) Broadcast(msg *message.Message) error
func (*MeteredClient) Middleware ¶
func (c *MeteredClient) Middleware(m message.Middleware)
func (*MeteredClient) Publish ¶ added in v0.2.0
func (c *MeteredClient) Publish(topic string, msg *message.Message) error
func (*MeteredClient) RegisterMessage ¶
func (c *MeteredClient) RegisterMessage(msg proto.Message)
func (*MeteredClient) Send ¶
func (c *MeteredClient) Send(msg *message.Message) (payloadSize int, err error)
func (*MeteredClient) Subscribe ¶ added in v0.2.0
func (c *MeteredClient) Subscribe(topic string) error
func (*MeteredClient) Unsubscribe ¶ added in v0.2.0
func (c *MeteredClient) Unsubscribe(topic string) error
type Option ¶
type Option func(cfg *Cfg)
func WithCompressionEnabled ¶
WithCompressionEnabled specifies if the client should try to negotiate compression (see https://datatracker.ietf.org/doc/html/rfc7692). Enabling this does not guarantee its success.
func WithHandShakeTimeout ¶
WithHandShakeTimeout set the time limit in which the websocket handshake should take place.
func WithHeartbeatInterval ¶
WithHeartbeatInterval introduces how often the Ping/Pong operation should take place. Right now, this is intended to keep alive connections. Defaults to 5 seconds.
func WithMaxConcurrency ¶
WithMaxConcurrency sets the concurrency level for handler execution. Values <= 1 means no concurrency, which means no goroutine scheduling takes place. Defaults to 10.
func WithOnCloseHook ¶
func WithOnCloseHook(h func()) Option
WithOnCloseHook allows the user registering function hooks for when the client reaches the ws.StatusClosed status.
Sending multiple times this option in the constructor will lead to function concatenation, so multiple hooks can be configured.
IMPORTANT NOTE: There's no panic catcher implementation here, ensure to implement it or ensure the underlying code does not panic.
func WithOnConfiguration ¶
WithOnConfiguration allows the user registering hook functions which will be invoked once the client is configured.
func WithOnErrorHook ¶
WithOnErrorHook allows the user registering function hooks for when an internal error happens, but cannot be returned in any way to the client. Like in processing loops.
IMPORTANT NOTE: There's no panic catcher implementation here, ensure to implement it or ensure the underlying code does not panic.
func WithOnStatusChangeHook ¶
WithOnStatusChangeHook allows the user registering function hooks for each status changes. Possible values for statuses can be found at go.eloylp.dev/goomerang/ws package.
Sending multiple times this option in the constructor will lead to function concatenation, so multiple hooks can be configured.
IMPORTANT NOTE: There's no panic catcher implementation here, ensure to implement it or ensure the underlying code does not panic.
func WithOnWorkerEnd ¶
func WithOnWorkerEnd(h func()) Option
WithOnWorkerEnd allows the user registering hook functions which will be invoked whenever a handler goroutine ends its operations. Only if concurrency is enabled by using WithMaxConcurrency option.
func WithOnWorkerStart ¶
func WithOnWorkerStart(h func()) Option
WithOnWorkerStart allows the user registering hook functions which will be invoked whenever a new handler goroutine is invoked. Only if concurrency is enabled by the WithMaxConcurrency option.
func WithReadBufferSize ¶
WithReadBufferSize configures the size in bytes of the read buffers for each connection. Defaults on 4096 bytes.
func WithServerAddr ¶
WithServerAddr configures the server to connect to.
func WithTLSConfig ¶
WithTLSConfig allows the user to pass a *tls.Config full setup to the client, in which encryption and authentication could be configured, by setting up a PKI (public key infrastructure).
func WithWriteBufferSize ¶
WithWriteBufferSize configures the size in bytes of the write buffers for each connection. Defaults on 4096 bytes.