Documentation ¶
Index ¶
- Variables
- type BroadcastResult
- type Cfg
- type MeteredServer
- func (s *MeteredServer) Broadcast(ctx context.Context, msg *message.Message) (brResult []BroadcastResult, err error)
- func (s *MeteredServer) Handle(msg proto.Message, handler message.Handler)
- func (s *MeteredServer) Middleware(m message.Middleware)
- func (s *MeteredServer) Publish(topic string, msg *message.Message) error
- func (s *MeteredServer) Run() (err error)
- func (s *MeteredServer) Shutdown(ctx context.Context) (err error)
- type Option
- func WithCompressionEnabled(b bool) Option
- func WithHTTPReadHeaderTimeout(t time.Duration) Option
- func WithHTTPReadTimeout(t time.Duration) Option
- func WithHTTPWriteTimeout(t time.Duration) Option
- func WithHandShakeTimeout(d time.Duration) Option
- func WithListenAddr(addr string) Option
- func WithMaxConcurrency(n int) Option
- func WithOnBroadcastHook(f func(fqdn string, result []BroadcastResult, duration time.Duration)) Option
- func WithOnClientBroadcastHook(f func(fqdn string)) Option
- func WithOnCloseHook(h func()) Option
- func WithOnConfiguration(h func(cfg *Cfg)) Option
- func WithOnErrorHook(h func(err error)) Option
- func WithOnPublishHook(f func(topic, fqdn string)) Option
- func WithOnStatusChangeHook(h func(status uint32)) Option
- func WithOnSubscribeHook(f func(topic string)) Option
- func WithOnUnsubscribeHook(f func(topic string)) Option
- func WithOnWorkerEnd(h func()) Option
- func WithOnWorkerStart(h func()) Option
- func WithReadBufferSize(s int) Option
- func WithTLSConfig(tlsConfig *tls.Config) Option
- func WithWriteBufferSize(s int) Option
- type Server
- func (s *Server) Addr() string
- func (s *Server) Broadcast(ctx context.Context, msg *message.Message) (brResult []BroadcastResult, err error)
- func (s *Server) Handle(msg proto.Message, handler message.Handler)
- func (s *Server) Middleware(m message.Middleware)
- func (s *Server) Publish(topic string, msg *message.Message) error
- func (s *Server) RegisterMessage(msg proto.Message)
- func (s *Server) Registry() message.Registry
- func (s *Server) Router() *http.ServeMux
- func (s *Server) Run() (err error)
- func (s *Server) Shutdown(ctx context.Context) (err error)
- type SyncSender
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BroadcastResult ¶
BroadcastResult represents the size and duration of each sent message during a broadcast operation. It provides information to the caller code.
type Cfg ¶
type Cfg struct { ListenURL string TLSConfig *tls.Config MaxConcurrency int ReadBufferSize int WriteBufferSize int HTTPWriteTimeout time.Duration HTTPReadTimeout time.Duration HTTPReadHeaderTimeout time.Duration HandshakeTimeout time.Duration EnableCompression bool // contains filtered or unexported fields }
type MeteredServer ¶
type MeteredServer struct {
// contains filtered or unexported fields
}
func NewMetered ¶
func NewMetered(m *metrics.ServerMetrics, opts ...Option) (*MeteredServer, error)
func (*MeteredServer) Broadcast ¶ added in v0.2.0
func (s *MeteredServer) Broadcast(ctx context.Context, msg *message.Message) (brResult []BroadcastResult, err error)
func (*MeteredServer) Handle ¶
func (s *MeteredServer) Handle(msg proto.Message, handler message.Handler)
func (*MeteredServer) Middleware ¶
func (s *MeteredServer) Middleware(m message.Middleware)
func (*MeteredServer) Publish ¶ added in v0.2.0
func (s *MeteredServer) Publish(topic string, msg *message.Message) error
func (*MeteredServer) Run ¶
func (s *MeteredServer) Run() (err error)
type Option ¶
type Option func(cfg *Cfg)
func WithCompressionEnabled ¶
WithCompressionEnabled specifies if the server should try to negotiate compression (see https://datatracker.ietf.org/doc/html/rfc7692). Enabling this does not guarantee its success.
func WithHTTPReadHeaderTimeout ¶
WithHTTPReadHeaderTimeout corresponds to the http.Server.ReadHeaderTimeout for this websocket server.
func WithHTTPReadTimeout ¶
WithHTTPReadTimeout correspond to the http.Server.ReadTimeout configuration for this websocket server.
func WithHTTPWriteTimeout ¶
WithHTTPWriteTimeout corresponds to the http.Server.WriteTimeout configuration for this websocket server.
func WithHandShakeTimeout ¶
WithHandShakeTimeout set the time limit in which the websocket handshake should take place.
func WithListenAddr ¶
WithListenAddr the address in which the server will listen to client connections.
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 WithOnBroadcastHook ¶ added in v0.2.0
func WithOnBroadcastHook(f func(fqdn string, result []BroadcastResult, duration time.Duration)) Option
WithOnBroadcastHook allows the user to inject a hook which will be executed on each successfully broadcast operation.
func WithOnClientBroadcastHook ¶ added in v0.2.0
WithOnClientBroadcastHook allows the user to inject a hook which will be executed each time a broadcast command arrives from the client.
func WithOnCloseHook ¶
func WithOnCloseHook(h func()) Option
WithOnCloseHook allows the user registering function hooks for when the server 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 server 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 user. 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 WithOnPublishHook ¶ added in v0.2.0
WithOnPublishHook allows the user to inject a hook which will be executed each time successfully publish operation takes place for a specific topic and message (fqdn).
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 WithOnSubscribeHook ¶ added in v0.2.0
WithOnSubscribeHook allows the user to inject a hook which will be executed each successfully subscribe to a specific topic, for a message.
func WithOnUnsubscribeHook ¶ added in v0.2.0
WithOnUnsubscribeHook allows the user to inject a hook which will be executed each time successfully unsubscribe from a specific topic, for a message.
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 WithTLSConfig ¶
WithTLSConfig allows the user to pass a *tls.Config full setup to the server, 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.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server will hold all subsystem and orchestration elements.
func (*Server) Addr ¶
Addr provides the listener address. It will return an empty string if it's not possible to determine the IP information.
func (*Server) Broadcast ¶ added in v0.2.0
func (s *Server) Broadcast(ctx context.Context, msg *message.Message) (brResult []BroadcastResult, err error)
Broadcast will try to send the provided message to all connected clients.
In case the provided context is canceled, the operation could be partially completed. It's recommended to always pass a context.WithTimeout().
The send operation will happen in parallel for each client.
In case of errors, it will continue the operation, keeping the first 100 ones and returning them in a multi-error type.
In case of success, the BroadcastResult return type will provide feedback, such as time distribution.
Calling this method it's intended to be thread safe.
func (*Server) Handle ¶
Handle registers a message handler in the server. It will panic if the server its already running.
func (*Server) Middleware ¶
func (s *Server) Middleware(m message.Middleware)
Middleware registers a middleware in the server. It will panic if the server its already running.
func (*Server) Publish ¶ added in v0.2.0
Publish enables the server to send a message to all subscribed clients in a topic.
func (*Server) RegisterMessage ¶ added in v0.2.0
RegisterMessage will make the server 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.
This is specially needed in order to make the server aware of the messages published in pub/sub patterns.
func (*Server) Router ¶ added in v0.3.0
Router provides access to the underlying HTTP router. The routes /ws and /wss are reserved for library operations.
func (*Server) Run ¶
Run will start the server with all the previously provided options.
The server instance it's not reusable. This method can be only executed once in the lifecycle of a server.
func (*Server) Shutdown ¶
Shutdown will start the graceful shutdown of the server.
The call to this function will block till the operation completes or the provided context expires.
A closing signal will be sent to all connected clients in parallel. Clients should then individually reply to this signal with another closing one. The server will wait a grace period of 5 seconds per each connection, before closing them.
This function will also wait for all the inflight message handlers and subsystems.
type SyncSender ¶
type SyncSender struct {
// contains filtered or unexported fields
}
func (*SyncSender) ConnSlot ¶ added in v0.2.0
func (s *SyncSender) ConnSlot() *conn.Slot