Documentation ¶
Overview ¶
Package wspubsub provides an easy way to publish/subscribe and receive messages over WebSocket protocol hiding the details of the underlying transport. The library based on the idea that all messages are published to channels. Subscribers will receive messages published to the channels to which they subscribe. The hub is responsible for defining the channels to which subscribers can subscribe.
Index ¶
- type Client
- type ClientConnectError
- type ClientFactory
- type ClientNotFoundError
- type ClientOptions
- type ClientPingError
- type ClientReceiveError
- type ClientRepeatConnectError
- type ClientSendBufferOverflowError
- type ClientSendError
- type ClientStore
- func (s *ClientStore) Channels(clientID UUID) ([]string, error)
- func (s *ClientStore) Count(channels ...string) int
- func (s *ClientStore) CountChannels(clientID UUID) (int, error)
- func (s *ClientStore) Find(fn IterateFunc, channels ...string) error
- func (s *ClientStore) Get(clientID UUID) (WebsocketClient, error)
- func (s *ClientStore) Set(client WebsocketClient)
- func (s *ClientStore) SetChannels(clientID UUID, channels ...string) error
- func (s *ClientStore) Unset(clientID UUID) error
- func (s *ClientStore) UnsetChannels(clientID UUID, channels ...string) error
- type ClientStoreOptions
- type ConnectHandler
- type ConnectionClosedError
- type DisconnectHandler
- type ErrorHandler
- type GobwasConnection
- type GobwasConnectionUpgrader
- type GobwasConnectionUpgraderOptions
- type GorillaConnection
- type GorillaConnectionUpgrader
- type GorillaConnectionUpgraderOptions
- type Hub
- func (h *Hub) Channels(clientID UUID) ([]string, error)
- func (h *Hub) Close() error
- func (h *Hub) Count(channels ...string) int
- func (h *Hub) Disconnect(clientID UUID) error
- func (h *Hub) IsSubscribed(clientID UUID) bool
- func (h *Hub) ListenAndServe(addr, path string) error
- func (h *Hub) ListenAndServeTLS(addr, path, certFile, keyFile string) error
- func (h *Hub) LogDebug(args ...interface{})
- func (h *Hub) LogDebugf(format string, args ...interface{})
- func (h *Hub) LogDebugln(args ...interface{})
- func (h *Hub) LogError(args ...interface{})
- func (h *Hub) LogErrorf(format string, args ...interface{})
- func (h *Hub) LogErrorln(args ...interface{})
- func (h *Hub) LogFatal(args ...interface{})
- func (h *Hub) LogFatalf(format string, args ...interface{})
- func (h *Hub) LogFatalln(args ...interface{})
- func (h *Hub) LogInfo(args ...interface{})
- func (h *Hub) LogInfof(format string, args ...interface{})
- func (h *Hub) LogInfoln(args ...interface{})
- func (h *Hub) LogPanic(args ...interface{})
- func (h *Hub) LogPanicf(format string, args ...interface{})
- func (h *Hub) LogPanicln(args ...interface{})
- func (h *Hub) LogPrint(args ...interface{})
- func (h *Hub) LogPrintf(format string, args ...interface{})
- func (h *Hub) LogPrintln(args ...interface{})
- func (h *Hub) LogWarn(args ...interface{})
- func (h *Hub) LogWarnf(format string, args ...interface{})
- func (h *Hub) LogWarnln(args ...interface{})
- func (h *Hub) OnConnect(handler ConnectHandler)
- func (h *Hub) OnDisconnect(handler DisconnectHandler)
- func (h *Hub) OnError(handler ErrorHandler)
- func (h *Hub) OnReceive(handler ReceiveHandler)
- func (h *Hub) Publish(message Message, channels ...string) (int, error)
- func (h *Hub) Send(clientID UUID, message Message) error
- func (h *Hub) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (h *Hub) Subscribe(clientID UUID, channels ...string) error
- func (h *Hub) Unsubscribe(clientID UUID, channels ...string) error
- type HubOptions
- type HubSubscriptionChannelRequired
- type IterateFunc
- type Logger
- type LogrusFormatter
- type LogrusLevel
- type LogrusLogger
- func (l LogrusLogger) Debug(args ...interface{})
- func (l LogrusLogger) Debugf(format string, args ...interface{})
- func (l LogrusLogger) Debugln(args ...interface{})
- func (l LogrusLogger) Error(args ...interface{})
- func (l LogrusLogger) Errorf(format string, args ...interface{})
- func (l LogrusLogger) Errorln(args ...interface{})
- func (l LogrusLogger) Fatal(args ...interface{})
- func (l LogrusLogger) Fatalf(format string, args ...interface{})
- func (l LogrusLogger) Fatalln(args ...interface{})
- func (l LogrusLogger) Info(args ...interface{})
- func (l LogrusLogger) Infof(format string, args ...interface{})
- func (l LogrusLogger) Infoln(args ...interface{})
- func (l LogrusLogger) Panic(args ...interface{})
- func (l LogrusLogger) Panicf(format string, args ...interface{})
- func (l LogrusLogger) Panicln(args ...interface{})
- func (l LogrusLogger) Print(args ...interface{})
- func (l LogrusLogger) Printf(format string, args ...interface{})
- func (l LogrusLogger) Println(args ...interface{})
- func (l LogrusLogger) Warn(args ...interface{})
- func (l LogrusLogger) Warnf(format string, args ...interface{})
- func (l LogrusLogger) Warnln(args ...interface{})
- type LogrusLoggerOptions
- type Message
- type MessageType
- type ReceiveHandler
- type SatoriUUIDGenerator
- type UUID
- type UUIDGenerator
- type WebsocketClient
- type WebsocketClientFactory
- type WebsocketClientStore
- type WebsocketConnection
- type WebsocketConnectionUpgrader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a connection to the WebSocket server.
func NewClient ¶
func NewClient(options ClientOptions, id UUID, upgrader WebsocketConnectionUpgrader, logger Logger) *Client
NewClient initializes a new Client.
func (*Client) OnError ¶
func (c *Client) OnError(handler ErrorHandler)
OnError registers a handler for errors occurred while reading or writing connection.
func (*Client) OnReceive ¶
func (c *Client) OnReceive(handler ReceiveHandler)
OnReceive registers a handler for incoming messages.
type ClientConnectError ¶
ClientConnectError returned when HTTP connection can't be upgraded to WebSocket connection.
func IsClientConnectError ¶
func IsClientConnectError(err error) (*ClientConnectError, bool)
IsClientConnectError checks if error type is ClientConnectError.
func NewClientConnectError ¶
func NewClientConnectError(id UUID, err error) *ClientConnectError
NewClientConnectError initializes a new ClientConnectError.
func (*ClientConnectError) Error ¶
func (e *ClientConnectError) Error() string
ClientConnectError implements an error interface.
type ClientFactory ¶
type ClientFactory struct {
// contains filtered or unexported fields
}
ClientFactory is responsible for creating a client.
func NewClientFactory ¶
func NewClientFactory( options ClientOptions, uuidGenerator UUIDGenerator, upgrader WebsocketConnectionUpgrader, logger Logger, ) *ClientFactory
NewClientFactory initializes a new ClientFactory.
func (*ClientFactory) Create ¶
func (f *ClientFactory) Create() WebsocketClient
Create returns a new client.
type ClientNotFoundError ¶
type ClientNotFoundError struct {
ID UUID
}
ClientNotFoundError returned when client is not present in a storage.
func IsClientNotFoundError ¶
func IsClientNotFoundError(err error) (*ClientNotFoundError, bool)
IsClientNotFoundError checks if error type is ClientNotFoundError.
func NewClientNotFoundError ¶
func NewClientNotFoundError(id UUID) *ClientNotFoundError
NewClientNotFoundError initializes a new ClientNotFoundError.
func (*ClientNotFoundError) Error ¶
func (e *ClientNotFoundError) Error() string
ClientNotFoundError implements an error interface.
type ClientOptions ¶
type ClientOptions struct { // How often pings will be sent by the client. PingInterval time.Duration // Max size of the buffer for messages which client should // write to a WebSocket connection. // Exceeding this size will cause an error. SendBufferSize int // Enable/disable debug mode. IsDebug bool // Function execution time limit in debug mode. // Exceeding this time limit will cause a new warn log message. DebugFuncTimeLimit time.Duration }
ClientOptions represents configuration of the client.
func NewClientOptions ¶
func NewClientOptions() ClientOptions
NewClientOptions initializes a new ClientOptions. nolint: gomnd
type ClientPingError ¶
ClientPingError returned when ping message can't be written to a WebSocket connection.
func IsClientPingError ¶
func IsClientPingError(err error) (*ClientPingError, bool)
IsClientPingError checks if error type is ClientPingError.
func NewClientPingError ¶
func NewClientPingError(id UUID, message Message, err error) *ClientPingError
NewClientPingError initializes a new ClientPingError.
func (*ClientPingError) Error ¶
func (e *ClientPingError) Error() string
ClientPingError implements an error interface.
type ClientReceiveError ¶
ClientReceiveError returned when message can't be read from a WebSocket connection.
func IsClientReceiveError ¶
func IsClientReceiveError(err error) (*ClientReceiveError, bool)
IsClientReceiveError checks if error type is ClientReceiveError.
func NewClientReceiveError ¶
func NewClientReceiveError(id UUID, message Message, err error) *ClientReceiveError
NewClientReceiveError initializes a new ClientReceiveError.
func (*ClientReceiveError) Error ¶
func (e *ClientReceiveError) Error() string
ClientReceiveError implements an error interface.
type ClientRepeatConnectError ¶
type ClientRepeatConnectError struct {
ID UUID
}
ClientRepeatConnectError returned when trying to connect an already connected client.
func IsClientRepeatConnectError ¶
func IsClientRepeatConnectError(err error) (*ClientRepeatConnectError, bool)
IsClientRepeatConnectError checks if error type is ClientRepeatConnectError.
func NewClientRepeatConnectError ¶
func NewClientRepeatConnectError(id UUID) *ClientRepeatConnectError
NewClientRepeatConnectError initializes a new ClientRepeatConnectError.
func (*ClientRepeatConnectError) Error ¶
func (e *ClientRepeatConnectError) Error() string
ClientRepeatConnectError implements an error interface.
type ClientSendBufferOverflowError ¶
type ClientSendBufferOverflowError struct {
ID UUID
}
ClientSendBufferOverflowError returned when client send buffer is full.
func IsClientSendBufferOverflowError ¶
func IsClientSendBufferOverflowError(err error) (*ClientSendBufferOverflowError, bool)
IsClientSendBufferOverflowError checks if error type is ClientSendBufferOverflowError.
func NewClientSendBufferOverflowError ¶
func NewClientSendBufferOverflowError(id UUID) *ClientSendBufferOverflowError
NewClientSendBufferOverflowError initializes a new ClientSendBufferOverflowError.
func (*ClientSendBufferOverflowError) Error ¶
func (e *ClientSendBufferOverflowError) Error() string
ClientSendBufferOverflowError implements an error interface.
type ClientSendError ¶
ClientSendError returned when a message (text or binary) can't be written to a WebSocket connection.
func IsClientSendError ¶
func IsClientSendError(err error) (*ClientSendError, bool)
IsClientSendError checks if error type is ClientSendError.
func NewClientSendError ¶
func NewClientSendError(id UUID, message Message, err error) *ClientSendError
NewClientSendError initializes a new ClientSendError.
func (*ClientSendError) Error ¶
func (e *ClientSendError) Error() string
ClientSendError implements an error interface.
type ClientStore ¶
type ClientStore struct {
// contains filtered or unexported fields
}
ClientStore represents the storage of clients.
func NewClientStore ¶
func NewClientStore(options ClientStoreOptions, logger Logger) *ClientStore
NewClientStore initializes a new ClientStore.
func (*ClientStore) Channels ¶
func (s *ClientStore) Channels(clientID UUID) ([]string, error)
CountChannels return a list of channels linked with the client.
func (*ClientStore) Count ¶
func (s *ClientStore) Count(channels ...string) int
Count returns the total number of clients in specified channel(-s).
func (*ClientStore) CountChannels ¶
func (s *ClientStore) CountChannels(clientID UUID) (int, error)
CountChannels return the total number of channels linked with the client.
func (*ClientStore) Find ¶
func (s *ClientStore) Find(fn IterateFunc, channels ...string) error
Find iterates over clients who subscribed on specified channel(-s).
func (*ClientStore) Get ¶
func (s *ClientStore) Get(clientID UUID) (WebsocketClient, error)
Get returns client by its ID.
func (*ClientStore) Set ¶
func (s *ClientStore) Set(client WebsocketClient)
Set puts client to storage.
func (*ClientStore) SetChannels ¶
func (s *ClientStore) SetChannels(clientID UUID, channels ...string) error
SetChannels links the client with specified channel(-s).
func (*ClientStore) Unset ¶
func (s *ClientStore) Unset(clientID UUID) error
Unset removes client from storage by its ID
func (*ClientStore) UnsetChannels ¶
func (s *ClientStore) UnsetChannels(clientID UUID, channels ...string) error
SetChannels unlinks the client from specified channel(-s). If channels were not specified then the client will be unlinked from all channels.
type ClientStoreOptions ¶
type ClientStoreOptions struct { ClientShards struct { // Total number of shards Count int // Size of shard Size int // Size of a bucket in shard BucketSize int } ChannelShards struct { // Total number of shards Count int // Size of shard Size int // Size of a bucket in shard BucketSize int } // Enable/disable debug mode. IsDebug bool // Function execution time limit in debug mode. // Exceeding this time limit will cause a new warn log message. DebugFuncTimeLimit time.Duration }
ClientStoreOptions represents configuration of the storage.
func NewClientStoreOptions ¶
func NewClientStoreOptions() ClientStoreOptions
NewClientStoreOptions initializes a new ClientStoreOptions. nolint: gomnd
type ConnectHandler ¶
type ConnectHandler func(clientID UUID)
ConnectHandler called when a new client is connected to hub.
type ConnectionClosedError ¶
type ConnectionClosedError struct {
Err error
}
ConnectionClosedError returned when trying to read or write to closed WebSocket connection.
func IsConnectionClosedError ¶
func IsConnectionClosedError(err error) (*ConnectionClosedError, bool)
IsConnectionClosedError checks if error type is ConnectionClosedError.
func NewConnectionClosedError ¶
func NewConnectionClosedError(err error) *ConnectionClosedError
NewConnectionClosedError initializes a new ConnectionClosedError.
func (*ConnectionClosedError) Error ¶
func (e *ConnectionClosedError) Error() string
ConnectionClosedError implements an error interface.
type DisconnectHandler ¶
type DisconnectHandler func(clientID UUID)
DisconnectHandler called when a client is disconnected from the hub.
type ErrorHandler ¶
ErrorHandler called when an error occurred when reading or writing messages.
type GobwasConnection ¶
type GobwasConnection struct { IsDebug bool DebugFuncTimeLimit time.Duration // contains filtered or unexported fields }
GobwasConnection is an implementation of WebsocketConnection.
func (*GobwasConnection) Close ¶
func (c *GobwasConnection) Close() error
Close closes a WebSocket connection.
func (*GobwasConnection) Read ¶
func (c *GobwasConnection) Read() (Message, error)
Read reads a message from WebSocket connection.
func (*GobwasConnection) Write ¶
func (c *GobwasConnection) Write(message Message) error
Write writes a message to WebSocket connection.
type GobwasConnectionUpgrader ¶
type GobwasConnectionUpgrader struct {
// contains filtered or unexported fields
}
GobwasConnectionUpgrader is an implementation of WebsocketConnectionUpgrader.
func NewGobwasConnectionUpgrader ¶
func NewGobwasConnectionUpgrader(options GobwasConnectionUpgraderOptions, logger Logger) *GobwasConnectionUpgrader
NewGobwasConnectionUpgrader initializes a new GobwasConnectionUpgrader.
func (*GobwasConnectionUpgrader) Upgrade ¶
func (u *GobwasConnectionUpgrader) Upgrade(w http.ResponseWriter, r *http.Request) (WebsocketConnection, error)
GobwasConnectionUpgrader upgrades HTTP connection to the WebSocket connection.
type GobwasConnectionUpgraderOptions ¶
type GobwasConnectionUpgraderOptions struct { ReadTimout time.Duration WriteTimout time.Duration IsDebug bool DebugFuncTimeLimit time.Duration }
GobwasConnectionUpgraderOptions represents configuration of the GobwasConnectionUpgrader.
func NewGobwasConnectionUpgraderOptions ¶
func NewGobwasConnectionUpgraderOptions() GobwasConnectionUpgraderOptions
NewGobwasUpgraderOptions initializes a new GobwasConnectionUpgraderOptions. nolint: gomnd
type GorillaConnection ¶
type GorillaConnection struct { IsDebug bool DebugFuncTimeLimit time.Duration // contains filtered or unexported fields }
GorillaConnection is an implementation of WebsocketConnection.
func (*GorillaConnection) Close ¶
func (c *GorillaConnection) Close() error
Close closes a WebSocket connection.
func (*GorillaConnection) Read ¶
func (c *GorillaConnection) Read() (Message, error)
Read reads a message from WebSocket connection.
func (*GorillaConnection) Write ¶
func (c *GorillaConnection) Write(message Message) error
Write writes a message to WebSocket connection.
type GorillaConnectionUpgrader ¶
type GorillaConnectionUpgrader struct {
// contains filtered or unexported fields
}
GorillaConnectionUpgrader is an implementation of WebsocketConnectionUpgrader.
func NewGorillaConnectionUpgrader ¶
func NewGorillaConnectionUpgrader(options GorillaConnectionUpgraderOptions, logger Logger) *GorillaConnectionUpgrader
NewGorillaConnectionUpgrader initializes a new GorillaConnectionUpgrader.
func (*GorillaConnectionUpgrader) Upgrade ¶
func (u *GorillaConnectionUpgrader) Upgrade(w http.ResponseWriter, r *http.Request) (WebsocketConnection, error)
GorillaConnectionUpgrader upgrades HTTP connection to the WebSocket connection.
type GorillaConnectionUpgraderOptions ¶
type GorillaConnectionUpgraderOptions struct { MaxMessageSize int64 ReadTimout time.Duration WriteTimout time.Duration HandshakeTimeout time.Duration ReadBufferSize int WriteBufferSize int Subprotocols []string Error func(w http.ResponseWriter, r *http.Request, status int, reason error) CheckOrigin func(r *http.Request) bool EnableCompression bool IsDebug bool DebugFuncTimeLimit time.Duration }
GorillaConnectionUpgraderOptions represents configuration of the GorillaConnectionUpgrader.
func NewGorillaConnectionUpgraderOptions ¶
func NewGorillaConnectionUpgraderOptions() GorillaConnectionUpgraderOptions
NewGorillaConnectionUpgraderOptions initializes a new GorillaConnectionUpgraderOptions. nolint: gomnd
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages client connections.
func NewDefaultHub ¶
func NewDefaultHub() *Hub
NewDefaultHub uses default dependencies to initializes a new hub.
func NewHub ¶
func NewHub( options HubOptions, clientStore WebsocketClientStore, clientFactory WebsocketClientFactory, logger Logger, ) *Hub
NewHub initializes a new Hub.
func (*Hub) Disconnect ¶
Disconnect closes a client connection and removes it from the storage.
func (*Hub) IsSubscribed ¶
IsSubscribed checks does the client is subscribed to at least one channel.
func (*Hub) ListenAndServe ¶
ListenAndServe listens on the TCP network address and handle requests on incoming connections.
func (*Hub) ListenAndServeTLS ¶
ListenAndServe listens on the TCP network address and handle requests on incoming connections.
func (*Hub) LogDebug ¶
func (h *Hub) LogDebug(args ...interface{})
LogDebug logs a message at level Debug.
func (*Hub) LogDebugln ¶
func (h *Hub) LogDebugln(args ...interface{})
LogDebugln is like LogDebug but adds a new line.
func (*Hub) LogError ¶
func (h *Hub) LogError(args ...interface{})
LogError logs a message at level Error.
func (*Hub) LogErrorln ¶
func (h *Hub) LogErrorln(args ...interface{})
LogErrorln is like LogError but adds a new line.
func (*Hub) LogFatal ¶
func (h *Hub) LogFatal(args ...interface{})
Fatal logs a message at level Fatal then the process will exit with status set to 1.
func (*Hub) LogFatalln ¶
func (h *Hub) LogFatalln(args ...interface{})
LogFatalln is like LogFatal but adds a new line.
func (*Hub) LogInfo ¶
func (h *Hub) LogInfo(args ...interface{})
LogInfo logs a message at level Info.
func (*Hub) LogInfoln ¶
func (h *Hub) LogInfoln(args ...interface{})
LogInfoln is like LogInfo but adds a new line.
func (*Hub) LogPanic ¶
func (h *Hub) LogPanic(args ...interface{})
Panic logs a message at level Panic and panics.
func (*Hub) LogPanicln ¶
func (h *Hub) LogPanicln(args ...interface{})
LogPanicln is like LogPanic but adds a new line.
func (*Hub) LogPrint ¶
func (h *Hub) LogPrint(args ...interface{})
LogPrint logs a message at level Info.
func (*Hub) LogPrintln ¶
func (h *Hub) LogPrintln(args ...interface{})
LogPrintln is like LogPrint but adds a new line.
func (*Hub) LogWarn ¶
func (h *Hub) LogWarn(args ...interface{})
LogWarn logs a message at level Warn.
func (*Hub) LogWarnln ¶
func (h *Hub) LogWarnln(args ...interface{})
LogWarnln is like LogWarn but adds a new line.
func (*Hub) OnConnect ¶
func (h *Hub) OnConnect(handler ConnectHandler)
OnConnect registers a handler for client connection.
func (*Hub) OnDisconnect ¶
func (h *Hub) OnDisconnect(handler DisconnectHandler)
OnDisconnect registers a handler for client disconnection.
func (*Hub) OnError ¶
func (h *Hub) OnError(handler ErrorHandler)
OnError registers a handler for errors occurred while reading or writing connection.
func (*Hub) OnReceive ¶
func (h *Hub) OnReceive(handler ReceiveHandler)
OnReceive registers a handler for incoming messages.
func (*Hub) Publish ¶
Publish publishes a message to the channels. If channels were not specified then all clients will receive the message.
func (*Hub) ServeHTTP ¶
func (h *Hub) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP implements http.Handler interface and responsible for connect new clients.
type HubOptions ¶
type HubOptions struct { // Time to gracefully shutdown a server ShutdownTimeout time.Duration // Enable/disable debug mode. IsDebug bool // Function execution time limit in debug mode. // Exceeding this time limit will cause a new warn log message. DebugFuncTimeLimit time.Duration }
HubOptions represents configuration of the hub.
func NewHubOptions ¶
func NewHubOptions() HubOptions
NewHubOptions initializes a new HubOptions. nolint: gomnd
type HubSubscriptionChannelRequired ¶
type HubSubscriptionChannelRequired struct {
// contains filtered or unexported fields
}
HubSubscriptionChannelRequired returned when trying to subscribe with an empty channels list.
func IsHubSubscriptionChannelRequiredError ¶
func IsHubSubscriptionChannelRequiredError(err error) (*HubSubscriptionChannelRequired, bool)
IsHubSubscriptionChannelRequiredError checks if error type is HubSubscriptionChannelRequired.
func NewHubSubscriptionChannelRequiredError ¶
func NewHubSubscriptionChannelRequiredError() *HubSubscriptionChannelRequired
NewHubSubscriptionChannelRequiredError initializes a new HubSubscriptionChannelRequired.
func (*HubSubscriptionChannelRequired) Error ¶
func (e *HubSubscriptionChannelRequired) Error() string
HubSubscriptionChannelRequired implements an error interface.
type IterateFunc ¶
type IterateFunc func(client WebsocketClient) error
IterateFunc is the type of the function called for each client visited by Find.
type Logger ¶
type Logger interface { Debug(args ...interface{}) Info(args ...interface{}) Print(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) Debugln(args ...interface{}) Infoln(args ...interface{}) Println(args ...interface{}) Warnln(args ...interface{}) Errorln(args ...interface{}) Fatalln(args ...interface{}) Panicln(args ...interface{}) Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Printf(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Panicf(format string, args ...interface{}) }
Logger is an interface representing the ability to log messages.
type LogrusFormatter ¶
type LogrusFormatter uint32
LogrusFormatter enumerates possible formatters.
const ( // LogrusFormatterText formats logs into text. LogrusFormatterText LogrusFormatter = iota // LogrusFormatterJSON formats logs into parsable JSON. LogrusFormatterJSON )
type LogrusLevel ¶
type LogrusLevel uint32
LogrusLevel enumerates possible logging levels.
const ( LogrusLevelPanic LogrusLevel = iota LogrusLevelFatal LogrusLevelError LogrusLevelWarn LogrusLevelInfo LogrusLevelDebug LogrusLevelTrace )
type LogrusLogger ¶
type LogrusLogger struct {
// contains filtered or unexported fields
}
LogrusLogger is an implementation of Logger.
func NewLogrusLogger ¶
func NewLogrusLogger(options LogrusLoggerOptions) *LogrusLogger
NewLogrusLogger initializes a new LogrusLogger.
func (LogrusLogger) Debug ¶
func (l LogrusLogger) Debug(args ...interface{})
Debug logs a message at level Debug.
func (LogrusLogger) Debugf ¶
func (l LogrusLogger) Debugf(format string, args ...interface{})
Debugf is like LogDebug but allows specifying a message format.
func (LogrusLogger) Debugln ¶
func (l LogrusLogger) Debugln(args ...interface{})
Debugln is like LogDebug but adds a new line.
func (LogrusLogger) Error ¶
func (l LogrusLogger) Error(args ...interface{})
Error logs a message at level Error.
func (LogrusLogger) Errorf ¶
func (l LogrusLogger) Errorf(format string, args ...interface{})
Errorf is like LogError but allows specifying a message format.
func (LogrusLogger) Errorln ¶
func (l LogrusLogger) Errorln(args ...interface{})
Errorln is like LogError but adds a new line.
func (LogrusLogger) Fatal ¶
func (l LogrusLogger) Fatal(args ...interface{})
Fatal logs a message at level Fatal then the process will exit with status set to 1.
func (LogrusLogger) Fatalf ¶
func (l LogrusLogger) Fatalf(format string, args ...interface{})
Fatalf is like LogFatal but allows specifying a message format.
func (LogrusLogger) Fatalln ¶
func (l LogrusLogger) Fatalln(args ...interface{})
Fatalln is like LogFatal but adds a new line.
func (LogrusLogger) Info ¶
func (l LogrusLogger) Info(args ...interface{})
Info logs a message at level Info.
func (LogrusLogger) Infof ¶
func (l LogrusLogger) Infof(format string, args ...interface{})
Infof is like LogInfo but allows specifying a message format.
func (LogrusLogger) Infoln ¶
func (l LogrusLogger) Infoln(args ...interface{})
Infoln is like LogInfo but adds a new line.
func (LogrusLogger) Panic ¶
func (l LogrusLogger) Panic(args ...interface{})
Panic logs a message at level Panic and panics.
func (LogrusLogger) Panicf ¶
func (l LogrusLogger) Panicf(format string, args ...interface{})
Panicf is like LogPanic but allows specifying a message format.
func (LogrusLogger) Panicln ¶
func (l LogrusLogger) Panicln(args ...interface{})
Panicln is like LogPanic but adds a new line.
func (LogrusLogger) Print ¶
func (l LogrusLogger) Print(args ...interface{})
Print logs a message at level Info.
func (LogrusLogger) Printf ¶
func (l LogrusLogger) Printf(format string, args ...interface{})
Printf is like LogPrint but allows specifying a message format.
func (LogrusLogger) Println ¶
func (l LogrusLogger) Println(args ...interface{})
Println is like LogPrint but adds a new line.
func (LogrusLogger) Warn ¶
func (l LogrusLogger) Warn(args ...interface{})
Warn logs a message at level Warn.
func (LogrusLogger) Warnf ¶
func (l LogrusLogger) Warnf(format string, args ...interface{})
Warnf is like LogWarn but allows specifying a message format.
func (LogrusLogger) Warnln ¶
func (l LogrusLogger) Warnln(args ...interface{})
Warnln is like LogWarn but adds a new line.
type LogrusLoggerOptions ¶
type LogrusLoggerOptions struct { Level LogrusLevel Formatter LogrusFormatter Output io.Writer }
LogrusLoggerOptions represents configuration of the LogrusLogger.
func NewLogrusLoggerOptions ¶
func NewLogrusLoggerOptions() LogrusLoggerOptions
NewLogrusLoggerOptions initializes a new LogrusLoggerOptions.
type Message ¶
type Message struct { Type MessageType Payload []byte }
Message represents a data type to send over a WebSocket connection.
func NewBinaryMessage ¶
NewBinaryMessage initializes a new binary Message from bytes.
func NewBinaryMessageFromString ¶
NewBinaryMessageFromString initializes a new binary Message from string.
func NewTextMessage ¶
NewTextMessage initializes a new text Message from bytes.
func NewTextMessageFromString ¶
NewTextMessage initializes a new text Message from string.
type MessageType ¶
type MessageType byte
MessageType enumerates possible message types.
const ( MessageTypeText MessageType = 1 MessageTypeBinary MessageType = 2 MessageTypePing MessageType = 9 )
type ReceiveHandler ¶
ReceiveHandler called when a client reads a new message.
type SatoriUUIDGenerator ¶
type SatoriUUIDGenerator struct{}
SatoriUUIDGenerator is an implementation of UUIDGenerator.
func (SatoriUUIDGenerator) GenerateV4 ¶
func (s SatoriUUIDGenerator) GenerateV4() UUID
GenerateV4 returns random generated UUID.
type UUID ¶
type UUID [16]byte
UUID represents a type compliant with specification described in RFC 4122.
type UUIDGenerator ¶
type UUIDGenerator interface {
GenerateV4() UUID
}
UUIDGenerator generates UUID v4.
type WebsocketClient ¶
type WebsocketClient interface { ID() UUID Connect(response http.ResponseWriter, request *http.Request) error OnReceive(handler ReceiveHandler) OnError(handler ErrorHandler) Send(message Message) error Close() error }
WebsocketClient is an interface representing the ability to interact with WebSocket connection.
type WebsocketClientFactory ¶
type WebsocketClientFactory interface {
Create() WebsocketClient
}
WebsocketClientStore is an interface responsible for creating a client.
type WebsocketClientStore ¶
type WebsocketClientStore interface { Get(clientID UUID) (WebsocketClient, error) Set(client WebsocketClient) Unset(clientID UUID) error Count(channels ...string) int Find(fn IterateFunc, channels ...string) error Channels(clientID UUID) ([]string, error) CountChannels(clientID UUID) (int, error) SetChannels(clientID UUID, channels ...string) error UnsetChannels(clientID UUID, channels ...string) error }
WebsocketClientStore is an interface responsible for storing and finding the users.
type WebsocketConnection ¶
type WebsocketConnection interface { Read() (Message, error) Write(message Message) error Close() error }
WebsocketConnection represents a WebSocket connection.
type WebsocketConnectionUpgrader ¶
type WebsocketConnectionUpgrader interface {
Upgrade(w http.ResponseWriter, r *http.Request) (WebsocketConnection, error)
}
WebsocketConnectionUpgrader upgrades HTTP connection to the WebSocket connection.
Source Files ¶
- client.go
- client_connect_error.go
- client_factory.go
- client_not_found_error.go
- client_options.go
- client_ping_error.go
- client_receive_error.go
- client_repeat_connect_error.go
- client_send_buffer_overflow_error.go
- client_send_error.go
- client_store.go
- client_store_channels_shard.go
- client_store_clients_shard.go
- client_store_options.go
- connection_closed_error.go
- doc.go
- gobwas_connection.go
- gobwas_upgrader.go
- gobwas_upgrader_options.go
- gorilla_connection.go
- gorilla_upgrader.go
- gorilla_upgrader_options.go
- hub.go
- hub_options.go
- hub_subscription_channel_required_error.go
- logrus_logger.go
- logrus_options.go
- message.go
- satori_uuid_generator.go
- uuid.go
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |