Documentation
¶
Index ¶
- Constants
- Variables
- func AuthCookie(token, path string) *http.Cookie
- func NoAuthenticationWrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- func SetAuthHeaders(headers *http.Header, authOpts *AuthenticationOpts)
- type AuthenticationBackend
- type AuthenticationOpts
- type BasicAuthenticationBackend
- func (b *BasicAuthenticationBackend) Authenticate(username string, password string) (string, error)
- func (b *BasicAuthenticationBackend) DefaultUserRole(user string) string
- func (b *BasicAuthenticationBackend) Name() string
- func (b *BasicAuthenticationBackend) SetDefaultUserRole(role string)
- func (b *BasicAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- type ConnectionType
- type CrudClient
- func (c *CrudClient) Create(resource string, value interface{}) error
- func (c *CrudClient) Delete(resource string, id string) error
- func (c *CrudClient) Get(resource string, id string, value interface{}) error
- func (c *CrudClient) List(resource string, values interface{}) error
- func (c *CrudClient) Update(resource string, id string, value interface{}) error
- type DefaultWSSpeakerEventHandler
- type ExtraAsset
- type HtpasswdMapProvider
- type KeystoneAuthenticationBackend
- func (b *KeystoneAuthenticationBackend) Authenticate(username string, password string) (string, error)
- func (b *KeystoneAuthenticationBackend) CheckUser(token string) (string, error)
- func (b *KeystoneAuthenticationBackend) DefaultUserRole(user string) string
- func (b *KeystoneAuthenticationBackend) Name() string
- func (b *KeystoneAuthenticationBackend) SetDefaultUserRole(role string)
- func (b *KeystoneAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- type NoAuthenticationBackend
- func (h *NoAuthenticationBackend) Authenticate(username string, password string) (string, error)
- func (h *NoAuthenticationBackend) DefaultUserRole(user string) string
- func (h *NoAuthenticationBackend) Name() string
- func (b *NoAuthenticationBackend) SetDefaultUserRole(role string)
- func (h *NoAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
- type PathPrefix
- type RestClient
- type Route
- type Server
- func (s *Server) AddGlobalVar(key string, v interface{})
- func (s *Server) HandleFunc(path string, f auth.AuthenticatedHandlerFunc, ...)
- func (s *Server) Listen() error
- func (s *Server) ListenAndServe()
- func (s *Server) RegisterLoginRoute(authBackend AuthenticationBackend)
- func (s *Server) RegisterRoutes(routes []Route, auth AuthenticationBackend)
- func (s *Server) Serve()
- func (s *Server) ServeIndex(w http.ResponseWriter, r *auth.AuthenticatedRequest)
- func (s *Server) Stop()
- type User
- type WSClient
- type WSClientPool
- type WSConn
- func (c *WSConn) AddEventHandler(h WSSpeakerEventHandler)
- func (c *WSConn) Connect()
- func (c *WSConn) Disconnect()
- func (c *WSConn) GetAddrPort() (string, int)
- func (c *WSConn) GetClientProtocol() string
- func (c *WSConn) GetHeaders() http.Header
- func (c *WSConn) GetHost() string
- func (c *WSConn) GetRemoteHost() string
- func (c *WSConn) GetRemoteServiceType() common.ServiceType
- func (c *WSConn) GetServiceType() common.ServiceType
- func (c *WSConn) GetStatus() WSConnStatus
- func (c *WSConn) GetURL() *url.URL
- func (c *WSConn) IsConnected() bool
- func (c *WSConn) SendMessage(m WSMessage) error
- func (c *WSConn) SendRaw(b []byte) error
- type WSConnState
- type WSConnStatus
- type WSIncomerHandler
- type WSMasterElection
- type WSMasterEventHandler
- type WSMessage
- type WSPool
- func (s *WSPool) AddClient(c WSSpeaker) error
- func (s *WSPool) AddEventHandler(h WSSpeakerEventHandler)
- func (s *WSPool) BroadcastMessage(m WSMessage)
- func (s *WSPool) DisconnectAll()
- func (s *WSPool) GetName() string
- func (s *WSPool) GetSpeakerByRemoteHost(host string) WSSpeaker
- func (s *WSPool) GetSpeakers() (speakers []WSSpeaker)
- func (s *WSPool) GetSpeakersByType(serviceType common.ServiceType) (speakers []WSSpeaker)
- func (s *WSPool) GetStatus() map[string]WSConnStatus
- func (s *WSPool) OnConnected(c WSSpeaker)
- func (s *WSPool) OnDisconnected(c WSSpeaker)
- func (s *WSPool) OnMessage(c WSSpeaker, m WSMessage)
- func (s *WSPool) PickConnectedSpeaker() WSSpeaker
- func (s *WSPool) RemoveClient(c WSSpeaker) bool
- func (s *WSPool) SendMessageTo(m WSMessage, host string) error
- func (s *WSPool) Start()
- func (s *WSPool) Stop()
- type WSRawMessage
- type WSServer
- type WSSpeaker
- type WSSpeakerEventHandler
- type WSSpeakerPool
- type WSSpeakerStructMessageDispatcher
- type WSSpeakerStructMessageHandler
- type WSStructClientPool
- func (a *WSStructClientPool) AddClient(c WSSpeaker) error
- func (d WSStructClientPool) AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
- func (d WSStructClientPool) AddStructSpeaker(c *WSStructSpeaker)
- func (s *WSStructClientPool) Request(host string, request *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
- type WSStructMessage
- func (g WSStructMessage) Bytes(protocol string) []byte
- func (g *WSStructMessage) Debug() string
- func (g *WSStructMessage) DecodeObj(obj interface{}) error
- func (g *WSStructMessage) Reply(v interface{}, kind string, status int) *WSStructMessage
- func (g *WSStructMessage) UnmarshalObj(obj interface{}) error
- type WSStructMessageJSON
- type WSStructServer
- func (s WSStructServer) AddClient(c WSSpeaker) error
- func (d WSStructServer) AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
- func (d WSStructServer) AddStructSpeaker(c *WSStructSpeaker)
- func (s *WSStructServer) OnConnected(c WSSpeaker)
- func (s *WSStructServer) OnDisconnected(c WSSpeaker)
- func (s *WSStructServer) OnMessage(c WSSpeaker, m WSMessage)
- func (s *WSStructServer) Request(host string, request *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
- type WSStructSpeaker
- func (a WSStructSpeaker) AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
- func (p WSStructSpeaker) OnConnected(c WSSpeaker)
- func (p WSStructSpeaker) OnDisconnected(c WSSpeaker)
- func (s *WSStructSpeaker) OnMessage(c WSSpeaker, m WSMessage)
- func (s *WSStructSpeaker) Request(m *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
- func (s *WSStructSpeaker) Send(m WSMessage)
- type WSStructSpeakerPool
Constants ¶
const ( // WildcardNamespace is the namespace used as wildcard. It is used by listeners to filter callbacks. WildcardNamespace = "*" ProtobufProtocol = "protobuf" JsonProtocol = "json" )
Variables ¶
DefaultRequestTimeout default timeout used for Request/Reply JSON message.
Functions ¶
func AuthCookie ¶ added in v0.19.0
AuthCookie returns a authentication cookie
func NoAuthenticationWrap ¶ added in v0.19.0
func NoAuthenticationWrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
func SetAuthHeaders ¶ added in v0.19.0
func SetAuthHeaders(headers *http.Header, authOpts *AuthenticationOpts)
SetAuthHeaders apply all the cookie used for authentication to the header
Types ¶
type AuthenticationBackend ¶
type AuthenticationBackend interface {
Name() string
DefaultUserRole(user string) string
SetDefaultUserRole(role string)
Authenticate(username string, password string) (string, error)
Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
}
AuthenticationBackend is the interface of a authentication backend
func NewAuthenticationBackendByName ¶ added in v0.19.0
func NewAuthenticationBackendByName(name string) (backend AuthenticationBackend, err error)
NewAuthenticationBackendByName creates a new auth backend based on the name
type AuthenticationOpts ¶
type BasicAuthenticationBackend ¶
type BasicAuthenticationBackend struct {
*auth.BasicAuth
// contains filtered or unexported fields
}
func NewBasicAuthenticationBackend ¶ added in v0.4.0
func NewBasicAuthenticationBackend(name string, provider auth.SecretProvider, role string) (*BasicAuthenticationBackend, error)
func NewBasicAuthenticationBackendFromConfig ¶
func NewBasicAuthenticationBackendFromConfig(name string) (*BasicAuthenticationBackend, error)
func (*BasicAuthenticationBackend) Authenticate ¶
func (b *BasicAuthenticationBackend) Authenticate(username string, password string) (string, error)
func (*BasicAuthenticationBackend) DefaultUserRole ¶ added in v0.19.0
func (b *BasicAuthenticationBackend) DefaultUserRole(user string) string
DefaultUserRole returns the default user role
func (*BasicAuthenticationBackend) Name ¶ added in v0.19.0
func (b *BasicAuthenticationBackend) Name() string
Name returns the name of the backend
func (*BasicAuthenticationBackend) SetDefaultUserRole ¶ added in v0.19.0
func (b *BasicAuthenticationBackend) SetDefaultUserRole(role string)
SetDefaultUserRole defines the default user role
func (*BasicAuthenticationBackend) Wrap ¶
func (b *BasicAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
type ConnectionType ¶ added in v0.12.0
type ConnectionType int
const ( // TCP connection TCP ConnectionType = 1 + iota // TLS secure connection TLS // ExtraAssetPrefix is used for extra assets ExtraAssetPrefix = "/extra-statics" )
type CrudClient ¶
type CrudClient struct {
RestClient
}
func NewCrudClient ¶
func NewCrudClient(url *url.URL, authOpts *AuthenticationOpts) (*CrudClient, error)
func (*CrudClient) Create ¶
func (c *CrudClient) Create(resource string, value interface{}) error
func (*CrudClient) Delete ¶
func (c *CrudClient) Delete(resource string, id string) error
func (*CrudClient) Get ¶
func (c *CrudClient) Get(resource string, id string, value interface{}) error
func (*CrudClient) List ¶
func (c *CrudClient) List(resource string, values interface{}) error
func (*CrudClient) Update ¶
func (c *CrudClient) Update(resource string, id string, value interface{}) error
type DefaultWSSpeakerEventHandler ¶ added in v0.13.0
type DefaultWSSpeakerEventHandler struct {
}
DefaultWSSpeakerEventHandler implements stubs for the wsIncomingClientEventHandler interface
func (*DefaultWSSpeakerEventHandler) OnConnected ¶ added in v0.13.0
func (d *DefaultWSSpeakerEventHandler) OnConnected(c WSSpeaker)
OnConnected is called when the connection is established.
func (*DefaultWSSpeakerEventHandler) OnDisconnected ¶ added in v0.13.0
func (d *DefaultWSSpeakerEventHandler) OnDisconnected(c WSSpeaker)
OnDisconnected is called when the connection is closed or lost.
func (*DefaultWSSpeakerEventHandler) OnMessage ¶ added in v0.13.0
func (d *DefaultWSSpeakerEventHandler) OnMessage(c WSSpeaker, m WSMessage)
OnMessage is called when a message is received.
type ExtraAsset ¶ added in v0.15.0
type HtpasswdMapProvider ¶ added in v0.19.0
HtpasswdMapProvider defines a basic auth secret provider
func NewHtpasswdMapProvider ¶ added in v0.19.0
func NewHtpasswdMapProvider(users map[string]string) *HtpasswdMapProvider
NewHtpasswdMapProvider creates a new htpassword provider based on a map
func (*HtpasswdMapProvider) AddUser ¶ added in v0.19.0
func (h *HtpasswdMapProvider) AddUser(user, password string)
AddUser add a new user with the given password
func (*HtpasswdMapProvider) SecretProvider ¶ added in v0.19.0
func (h *HtpasswdMapProvider) SecretProvider() auth.SecretProvider
SecretProvider returns a SecretProvider
type KeystoneAuthenticationBackend ¶
type KeystoneAuthenticationBackend struct {
AuthURL string
Tenant string
Domain string
// contains filtered or unexported fields
}
func NewKeystoneAuthenticationBackendFromConfig ¶
func NewKeystoneAuthenticationBackendFromConfig(name string) (*KeystoneAuthenticationBackend, error)
func NewKeystoneBackend ¶
func (*KeystoneAuthenticationBackend) Authenticate ¶
func (b *KeystoneAuthenticationBackend) Authenticate(username string, password string) (string, error)
func (*KeystoneAuthenticationBackend) CheckUser ¶
func (b *KeystoneAuthenticationBackend) CheckUser(token string) (string, error)
func (*KeystoneAuthenticationBackend) DefaultUserRole ¶ added in v0.19.0
func (b *KeystoneAuthenticationBackend) DefaultUserRole(user string) string
DefaultUserRole return the default user role
func (*KeystoneAuthenticationBackend) Name ¶ added in v0.19.0
func (b *KeystoneAuthenticationBackend) Name() string
Name returns the name of the backend
func (*KeystoneAuthenticationBackend) SetDefaultUserRole ¶ added in v0.19.0
func (b *KeystoneAuthenticationBackend) SetDefaultUserRole(role string)
SetDefaultUserRole defines the default user role
func (*KeystoneAuthenticationBackend) Wrap ¶
func (b *KeystoneAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
type NoAuthenticationBackend ¶
type NoAuthenticationBackend struct {
}
func NewNoAuthenticationBackend ¶
func NewNoAuthenticationBackend() *NoAuthenticationBackend
func (*NoAuthenticationBackend) Authenticate ¶
func (h *NoAuthenticationBackend) Authenticate(username string, password string) (string, error)
func (*NoAuthenticationBackend) DefaultUserRole ¶ added in v0.19.0
func (h *NoAuthenticationBackend) DefaultUserRole(user string) string
DefaultUserRole returns the name of the backend
func (*NoAuthenticationBackend) Name ¶ added in v0.19.0
func (h *NoAuthenticationBackend) Name() string
Name returns the name of the backend
func (*NoAuthenticationBackend) SetDefaultUserRole ¶ added in v0.19.0
func (b *NoAuthenticationBackend) SetDefaultUserRole(role string)
SetDefaultUserRole defines the default user role
func (*NoAuthenticationBackend) Wrap ¶
func (h *NoAuthenticationBackend) Wrap(wrapped auth.AuthenticatedHandlerFunc) http.HandlerFunc
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
func NewRestClient ¶
func NewRestClient(url *url.URL, authOpts *AuthenticationOpts) (*RestClient, error)
type Route ¶
type Server ¶
type Server struct {
sync.RWMutex
http.Server
Host string
ServiceType common.ServiceType
Router *mux.Router
Addr string
Port int
AuthBackend AuthenticationBackend
CnxType ConnectionType
// contains filtered or unexported fields
}
func NewServer ¶
func NewServerFromConfig ¶
func NewServerFromConfig(serviceType common.ServiceType) (*Server, error)
func (*Server) AddGlobalVar ¶ added in v0.19.0
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(path string, f auth.AuthenticatedHandlerFunc, authBackend AuthenticationBackend)
HandleFunc specifies the handler function and the authentication backend used for a given path
func (*Server) RegisterLoginRoute ¶ added in v0.19.0
func (s *Server) RegisterLoginRoute(authBackend AuthenticationBackend)
func (*Server) RegisterRoutes ¶
func (s *Server) RegisterRoutes(routes []Route, auth AuthenticationBackend)
func (*Server) ServeIndex ¶ added in v0.19.0
func (s *Server) ServeIndex(w http.ResponseWriter, r *auth.AuthenticatedRequest)
ServeIndex servers the index page
type User ¶ added in v0.8.0
type WSClient ¶ added in v0.4.0
type WSClient struct {
*WSConn
Path string
AuthOpts *AuthenticationOpts
}
WSClient is a outgoint client meaning a client connected to a remote websocket server. It embeds a WSConn.
func NewWSClient ¶ added in v0.13.0
func NewWSClient(host string, clientType common.ServiceType, url *url.URL, authOpts *AuthenticationOpts, headers http.Header, queueSize int) *WSClient
NewWSClient returns a WSClient with a new connection.
func NewWSClientFromConfig ¶ added in v0.13.0
func NewWSClientFromConfig(clientType common.ServiceType, url *url.URL, authOpts *AuthenticationOpts, headers http.Header) *WSClient
NewWSClientFromConfig creates a WSClient based on the configuration
func (*WSClient) Connect ¶ added in v0.13.0
func (c *WSClient) Connect()
Connect to the server - and reconnect if necessary
func (*WSClient) UpgradeToWSStructSpeaker ¶ added in v0.17.0
func (c *WSClient) UpgradeToWSStructSpeaker() *WSStructSpeaker
type WSClientPool ¶ added in v0.13.0
type WSClientPool struct {
*WSPool
}
WSClientPool is a pool of out going WSSpeaker meaning connection to a remote WSServer.
func NewWSClientPool ¶ added in v0.13.0
func NewWSClientPool(name string) *WSClientPool
NewWSClientPool returns a new WSClientPool meaning a pool of outgoing WSClient.
func (*WSClientPool) ConnectAll ¶ added in v0.13.0
func (s *WSClientPool) ConnectAll()
ConnectAll calls connect to all the wSSpeakers of the pool.
type WSConn ¶ added in v0.13.0
type WSConn struct {
common.RWMutex
WSConnStatus
// contains filtered or unexported fields
}
WSConn is the connection object of a WSSpeaker
func (*WSConn) AddEventHandler ¶ added in v0.13.0
func (c *WSConn) AddEventHandler(h WSSpeakerEventHandler)
AddEventHandler registers a new event handler
func (*WSConn) Connect ¶ added in v0.13.0
func (c *WSConn) Connect()
Connect default implementation doing nothing as for incoming connection it is not used.
func (*WSConn) Disconnect ¶ added in v0.13.0
func (c *WSConn) Disconnect()
Disconnect the WSSpeakers without waiting for termination.
func (*WSConn) GetAddrPort ¶ added in v0.13.0
GetAddrPort returns the address and the port of the remote end.
func (*WSConn) GetClientProtocol ¶ added in v0.17.0
GetClientProtocol returns the websocket protocol.
func (*WSConn) GetHeaders ¶ added in v0.14.0
GetHeaders returns the client HTTP headers.
func (*WSConn) GetHost ¶ added in v0.13.0
GetHost returns the hostname/host-id of the connection.
func (*WSConn) GetRemoteHost ¶ added in v0.19.0
GetRemoteHost returns the hostname/host-id of the remote side of the connection.
func (*WSConn) GetRemoteServiceType ¶ added in v0.19.0
func (c *WSConn) GetRemoteServiceType() common.ServiceType
GetRemoteServiceType returns the remote service type.
func (*WSConn) GetServiceType ¶ added in v0.13.0
func (c *WSConn) GetServiceType() common.ServiceType
GetServiceType returns the client type.
func (*WSConn) GetStatus ¶ added in v0.13.0
func (c *WSConn) GetStatus() WSConnStatus
GetStatus returns the status of a WebSocket connection
func (*WSConn) GetURL ¶ added in v0.14.0
GetURL returns the URL of the connection
func (*WSConn) IsConnected ¶ added in v0.13.0
IsConnected returns the connection status.
func (*WSConn) SendMessage ¶ added in v0.13.0
SendMessage adds a message to sending queue.
type WSConnState ¶ added in v0.13.0
type WSConnState int32
WSConnState describes the connection state
func (*WSConnState) MarshalJSON ¶ added in v0.13.0
func (s *WSConnState) MarshalJSON() ([]byte, error)
func (*WSConnState) UnmarshalJSON ¶ added in v0.13.0
func (s *WSConnState) UnmarshalJSON(b []byte) error
UnmarshalJSON deserialize a connection state
type WSConnStatus ¶ added in v0.13.0
type WSConnStatus struct {
ServiceType common.ServiceType
ClientProtocol string
Addr string
Port int
Host string `json:"-"`
State *WSConnState `json:"IsConnected"`
URL *url.URL `json:"-"`
ConnectTime time.Time
RemoteHost string `json:",omitempty"`
RemoteServiceType common.ServiceType `json:",omitempty"`
// contains filtered or unexported fields
}
WSConnStatus describes the status of a WebSocket connection
type WSIncomerHandler ¶ added in v0.13.0
WSIncomerHandler incoming client handler interface.
type WSMasterElection ¶ added in v0.13.0
type WSMasterElection struct {
common.RWMutex
DefaultWSSpeakerEventHandler
// contains filtered or unexported fields
}
WSMasterElection provides a mechanism based on etcd to elect a master from a WSSpeakerPool.
func NewWSMasterElection ¶ added in v0.13.0
func NewWSMasterElection(pool WSSpeakerPool) *WSMasterElection
NewWSMasterElection returns a new WSMasterElection.
func (*WSMasterElection) AddEventHandler ¶ added in v0.13.0
func (a *WSMasterElection) AddEventHandler(eventHandler WSMasterEventHandler)
AddEventHandler a new WSMasterEventHandler event handler.
func (*WSMasterElection) GetMaster ¶ added in v0.13.0
func (a *WSMasterElection) GetMaster() WSSpeaker
GetMaster returns the current master.
func (*WSMasterElection) OnConnected ¶ added in v0.13.0
func (a *WSMasterElection) OnConnected(c WSSpeaker)
OnConnected is triggered when a new WSSpeaker get connected. If no master was elected this WSSpeaker will be chosen as master.
func (*WSMasterElection) OnDisconnected ¶ added in v0.13.0
func (a *WSMasterElection) OnDisconnected(c WSSpeaker)
OnDisconnected is triggered when a new WSSpeaker get disconnected. If it was the master a new election is triggered.
func (*WSMasterElection) SendMessageToMaster ¶ added in v0.13.0
func (a *WSMasterElection) SendMessageToMaster(m WSMessage)
SendMessageToMaster sends a message to the master.
type WSMasterEventHandler ¶ added in v0.13.0
type WSMasterEventHandler interface {
OnNewMaster(c WSSpeaker)
}
WSMasterEventHandler is the interface to be implemented by master election listeners.
type WSMessage ¶ added in v0.4.0
WSMessage is the interface of a message to send over the wire
type WSPool ¶ added in v0.13.0
WSPool is a connection container. It embed a list of WSSpeaker.
func (*WSPool) AddClient ¶ added in v0.13.0
AddClient adds the given WSSpeaker to the pool.
func (*WSPool) AddEventHandler ¶ added in v0.13.0
func (s *WSPool) AddEventHandler(h WSSpeakerEventHandler)
AddEventHandler registers a new event handler.
func (*WSPool) BroadcastMessage ¶ added in v0.13.0
BroadcastMessage broadcasts the given message.
func (*WSPool) DisconnectAll ¶ added in v0.13.0
func (s *WSPool) DisconnectAll()
DisconnectAll disconnects all the WSSpeaker
func (*WSPool) GetName ¶ added in v0.16.0
GetName returns the name of the pool
func (*WSPool) GetSpeakerByRemoteHost ¶ added in v0.19.0
GetSpeakerByRemoteHost returns the WSSpeaker for the given remote host.
func (*WSPool) GetSpeakers ¶ added in v0.13.0
GetSpeakers returns the WSSpeakers of the pool.
func (*WSPool) GetSpeakersByType ¶ added in v0.13.0
func (s *WSPool) GetSpeakersByType(serviceType common.ServiceType) (speakers []WSSpeaker)
GetSpeakersByType returns WSSpeakers matching the given type.
func (*WSPool) GetStatus ¶ added in v0.13.0
func (s *WSPool) GetStatus() map[string]WSConnStatus
GetStatus returns the states of the WebSocket clients
func (*WSPool) OnConnected ¶ added in v0.13.0
OnConnected forwards the OnConnected event to event listeners of the pool.
func (*WSPool) OnDisconnected ¶ added in v0.13.0
OnDisconnected forwards the OnConnected event to event listeners of the pool.
func (*WSPool) OnMessage ¶ added in v0.13.0
OnMessage forwards the OnMessage event to event listeners of the pool.
func (*WSPool) PickConnectedSpeaker ¶ added in v0.13.0
PickConnectedSpeaker returns randomly a connected WSSpeaker
func (*WSPool) RemoveClient ¶ added in v0.15.0
RemoveClient removes client from the pool
func (*WSPool) SendMessageTo ¶ added in v0.13.0
SendMessageTo sends message to WSSpeaker for the given remote host.
type WSRawMessage ¶ added in v0.13.0
type WSRawMessage []byte
WSRawMessage represents a raw message (array of bytes)
func (WSRawMessage) Bytes ¶ added in v0.13.0
func (m WSRawMessage) Bytes(protocol string) []byte
Bytes returns the string representation of the raw message
type WSServer ¶ added in v0.4.0
WSServer implements a websocket server. It owns a WSPool of incoming WSSpeakers.
func NewWSServer ¶ added in v0.4.0
func NewWSServer(server *Server, endpoint string, authBackend AuthenticationBackend) *WSServer
NewWSServer returns a new WSServer. The given auth backend will validate the credentials
func (WSServer) AddClient ¶ added in v0.14.0
AddClient adds the given WSSpeaker to the wsIncomerPool.
type WSSpeaker ¶ added in v0.13.0
type WSSpeaker interface {
GetStatus() WSConnStatus
GetHost() string
GetAddrPort() (string, int)
GetServiceType() common.ServiceType
GetClientProtocol() string
GetHeaders() http.Header
GetURL() *url.URL
IsConnected() bool
SendMessage(m WSMessage) error
SendRaw(r []byte) error
Connect()
Disconnect()
AddEventHandler(WSSpeakerEventHandler)
GetRemoteHost() string
GetRemoteServiceType() common.ServiceType
}
WSSpeaker is the interface for a websocket speaking client. It is used for outgoing or incoming connections.
type WSSpeakerEventHandler ¶ added in v0.13.0
type WSSpeakerEventHandler interface {
OnMessage(c WSSpeaker, m WSMessage)
OnConnected(c WSSpeaker)
OnDisconnected(c WSSpeaker)
}
WSSpeakerEventHandler is the interface to be implement by the client events listeners.
type WSSpeakerPool ¶ added in v0.13.0
type WSSpeakerPool interface {
AddClient(c WSSpeaker) error
RemoveClient(c WSSpeaker) bool
AddEventHandler(h WSSpeakerEventHandler)
GetSpeakers() []WSSpeaker
GetSpeakerByRemoteHost(host string) WSSpeaker
PickConnectedSpeaker() WSSpeaker
BroadcastMessage(m WSMessage)
SendMessageTo(m WSMessage, host string) error
}
WSSpeakerPool is the interface that WSSpeaker pools have to implement.
type WSSpeakerStructMessageDispatcher ¶ added in v0.17.0
type WSSpeakerStructMessageDispatcher interface {
AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
}
WSSpeakerStructMessageDispatcher interface is used to dispatch OnWSStructMessage events.
type WSSpeakerStructMessageHandler ¶ added in v0.17.0
type WSSpeakerStructMessageHandler interface {
OnWSStructMessage(c WSSpeaker, m *WSStructMessage)
}
WSSpeakerStructMessageHandler interface used to receive Struct messages.
type WSStructClientPool ¶ added in v0.17.0
type WSStructClientPool struct {
*WSClientPool
// contains filtered or unexported fields
}
WSStructClientPool is a WSClientPool able to send WSStructMessage.
func NewWSStructClientPool ¶ added in v0.17.0
func NewWSStructClientPool(name string) *WSStructClientPool
NewWSStructClientPool returns a new WSStructClientPool.
func (*WSStructClientPool) AddClient ¶ added in v0.17.0
func (a *WSStructClientPool) AddClient(c WSSpeaker) error
AddClient adds a WSClient to the pool.
func (WSStructClientPool) AddStructMessageHandler ¶ added in v0.17.0
func (d WSStructClientPool) AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
AddStructMessageHandler adds a new listener for Struct messages.
func (WSStructClientPool) AddStructSpeaker ¶ added in v0.17.0
func (d WSStructClientPool) AddStructSpeaker(c *WSStructSpeaker)
func (*WSStructClientPool) Request ¶ added in v0.17.0
func (s *WSStructClientPool) Request(host string, request *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
Request sends a Request Struct message to the WSSpeaker of the given remote host.
type WSStructMessage ¶ added in v0.17.0
type WSStructMessage struct {
Protocol string
Namespace string
Type string
UUID string
Status int64
JsonObj *json.RawMessage
ProtobufObj []byte
// contains filtered or unexported fields
}
func NewWSStructMessage ¶ added in v0.17.0
func NewWSStructMessage(ns string, tp string, v interface{}, uuids ...string) *WSStructMessage
NewWSStructMessage creates a new WSStructMessage with the given namespace, type, value and optionally the UUID.
func (WSStructMessage) Bytes ¶ added in v0.17.0
func (g WSStructMessage) Bytes(protocol string) []byte
Bytes see Marshal
func (*WSStructMessage) Debug ¶ added in v0.17.0
func (g *WSStructMessage) Debug() string
Debug representation of the struct WSStructMessage
func (*WSStructMessage) DecodeObj ¶ added in v0.17.0
func (g *WSStructMessage) DecodeObj(obj interface{}) error
func (*WSStructMessage) Reply ¶ added in v0.17.0
func (g *WSStructMessage) Reply(v interface{}, kind string, status int) *WSStructMessage
Reply returns a reply message with the given value, type and status. Basically it return a new WSStructMessage with the correct Namespace and UUID.
func (*WSStructMessage) UnmarshalObj ¶ added in v0.17.0
func (g *WSStructMessage) UnmarshalObj(obj interface{}) error
type WSStructMessageJSON ¶ added in v0.17.0
type WSStructMessageJSON struct {
Namespace string
Type string
UUID string
Status int64
Obj *json.RawMessage
}
func (*WSStructMessageJSON) Marshal ¶ added in v0.17.0
func (g *WSStructMessageJSON) Marshal() []byte
Marshal serializes the WSStructMessage into a JSON string.
type WSStructServer ¶ added in v0.17.0
type WSStructServer struct {
*WSServer
// contains filtered or unexported fields
}
WSStructServer is a WSServer able to handle WSStructSpeaker.
func NewWSStructServer ¶ added in v0.17.0
func NewWSStructServer(server *WSServer) *WSStructServer
NewWSStructServer returns a new WSStructServer
func (WSStructServer) AddClient ¶ added in v0.17.0
AddClient adds the given WSSpeaker to the wsIncomerPool.
func (WSStructServer) AddStructMessageHandler ¶ added in v0.17.0
func (d WSStructServer) AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
AddStructMessageHandler adds a new listener for Struct messages.
func (WSStructServer) AddStructSpeaker ¶ added in v0.17.0
func (d WSStructServer) AddStructSpeaker(c *WSStructSpeaker)
func (*WSStructServer) OnConnected ¶ added in v0.17.0
func (s *WSStructServer) OnConnected(c WSSpeaker)
OnConnected websocket event.
func (*WSStructServer) OnDisconnected ¶ added in v0.17.0
func (s *WSStructServer) OnDisconnected(c WSSpeaker)
OnDisconnected removes the WSSpeaker from the incomer pool.
func (*WSStructServer) OnMessage ¶ added in v0.17.0
func (s *WSStructServer) OnMessage(c WSSpeaker, m WSMessage)
OnMessage websocket event.
func (*WSStructServer) Request ¶ added in v0.17.0
func (s *WSStructServer) Request(host string, request *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
Request sends a Request Struct message to the WSSpeaker of the given remote host.
type WSStructSpeaker ¶ added in v0.17.0
type WSStructSpeaker struct {
WSSpeaker
// contains filtered or unexported fields
}
WSStructSpeaker is a WSSpeaker able to handle Struct Message and Request/Reply calls.
func (WSStructSpeaker) AddStructMessageHandler ¶ added in v0.17.0
func (a WSStructSpeaker) AddStructMessageHandler(h WSSpeakerStructMessageHandler, namespaces []string)
AddStructMessageHandler adds a new listener for Struct messages.
func (WSStructSpeaker) OnConnected ¶ added in v0.17.0
func (p WSStructSpeaker) OnConnected(c WSSpeaker)
OnConnected is implemented here to avoid infinite loop since the default implemtation is triggering OnDisconnected too.
func (WSStructSpeaker) OnDisconnected ¶ added in v0.17.0
func (p WSStructSpeaker) OnDisconnected(c WSSpeaker)
OnDisconnected is implemented here to avoid infinite loop since the default implemtation is triggering OnDisconnected too.
func (*WSStructSpeaker) OnMessage ¶ added in v0.17.0
func (s *WSStructSpeaker) OnMessage(c WSSpeaker, m WSMessage)
OnMessage checks that the WSMessage comes from a WSStructSpeaker. It parses the Struct message and then dispatch the message to the proper listeners according to the namespace.
func (*WSStructSpeaker) Request ¶ added in v0.17.0
func (s *WSStructSpeaker) Request(m *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
Request sends a Struct message request waiting for a reply using the given timeout.
func (*WSStructSpeaker) Send ¶ added in v0.17.0
func (s *WSStructSpeaker) Send(m WSMessage)
Send sends a message according to the namespace.
type WSStructSpeakerPool ¶ added in v0.17.0
type WSStructSpeakerPool interface {
WSSpeakerPool
WSSpeakerStructMessageDispatcher
Request(host string, request *WSStructMessage, timeout time.Duration) (*WSStructMessage, error)
}
WSStructSpeakerPool is the interface of a pool of WSStructSpeakers.
Source Files
¶
- auth.go
- basic.go
- basic_map_provider.go
- client.go
- keystone.go
- master.go
- noauth.go
- pool.go
- server.go
- tls.go
- wsclient.go
- wsmessage.go
- wsserver.go