Documentation
¶
Index ¶
- func DefaultLocalTransportPublish(tp *LocalTransport, network, chat, node string, payload interface{}) error
- func DispatchMsg(rcv Receiver, rawMsg []byte) error
- func MakeID(reqID string) string
- func Uint64ID(dest *strings.Builder, n uint64) int
- type ClientStateInfo
- type LocalTransport
- type MultiTransport
- func (tp *MultiTransport) AddTransport(transport Transporter)
- func (tp *MultiTransport) Advertise() error
- func (tp *MultiTransport) Close() error
- func (tp *MultiTransport) GetProtocol() string
- func (tp *MultiTransport) Publish(network, chat, node string, payload interface{}) error
- func (tp *MultiTransport) PublishError(id string, network string, err error) error
- func (tp *MultiTransport) RemoveTransport(transport Transporter)
- type MultiTransportError
- type MultiTransporter
- type Networker
- type NewClientFunc
- type Receiver
- type Service
- func (svc *Service) CheckArgs(n int, msg *stdchat.CmdMsg) bool
- func (svc *Service) Close() error
- func (svc *Service) Closed() bool
- func (svc *Service) CmdHandler(msg *stdchat.CmdMsg)
- func (svc *Service) Context() context.Context
- func (svc *Service) GenericError(err error)
- func (svc *Service) GetClientByNetwork(networkID string) Networker
- func (svc *Service) GetClients() []Networker
- func (svc *Service) GetStateInfo() ServiceStateInfo
- func (svc *Service) Handler(msg *stdchat.ChatMsg)
- func (svc *Service) Login(remote, userID, auth string, values stdchat.ValuesInfo, id string) (Networker, error)
- func (svc *Service) Logout(logoutID, reason string, values stdchat.ValuesInfo, id string) error
- func (svc *Service) OnClientClosed(client Networker)
- func (svc *Service) Protocol() string
- func (svc *Service) Transporter() Transporter
- type ServiceStateInfo
- type Servicer
- type SingleTransportError
- type Transporter
- type WebServer
- func (ws *WebServer) Close() error
- func (ws *WebServer) FindHandler(path string) http.Handler
- func (ws *WebServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (ws *WebServer) ServeURL(network, pathSuffix string, handler http.Handler) (string, error)
- func (ws *WebServer) StopServeURL(network, pathSuffix string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLocalTransportPublish ¶
func DefaultLocalTransportPublish(tp *LocalTransport, network, chat, node string, payload interface{}) error
func DispatchMsg ¶
DispatchMsg dispatches a raw input message to the receiver (service)
Types ¶
type ClientStateInfo ¶
type ClientStateInfo struct {
Network stdchat.NetworkStateInfo
Subscriptions []stdchat.SubscriptionStateInfo
}
type LocalTransport ¶
type LocalTransport struct {
Protocol string
PublishHandler func(tp *LocalTransport,
network, chat, node string, payload interface{}) error
WebServer
}
LocalTransport is a service transport for local use. All fields optional.
func (*LocalTransport) Advertise ¶
func (tp *LocalTransport) Advertise() error
func (*LocalTransport) GetProtocol ¶
func (tp *LocalTransport) GetProtocol() string
func (*LocalTransport) Publish ¶
func (tp *LocalTransport) Publish(network, chat, node string, payload interface{}) error
func (*LocalTransport) PublishError ¶
func (tp *LocalTransport) PublishError(id string, network string, err error) error
type MultiTransport ¶
MultiTransport relays messages to zero or more other transports. It is thread safe.
func (*MultiTransport) AddTransport ¶
func (tp *MultiTransport) AddTransport(transport Transporter)
func (*MultiTransport) Advertise ¶
func (tp *MultiTransport) Advertise() error
func (*MultiTransport) Close ¶
func (tp *MultiTransport) Close() error
func (*MultiTransport) GetProtocol ¶
func (tp *MultiTransport) GetProtocol() string
func (*MultiTransport) Publish ¶
func (tp *MultiTransport) Publish(network, chat, node string, payload interface{}) error
Publish will be called on all the added transports, errors will be collected into a *MultiTransportError if more than one error, *SingleTransportError if just one error, or nil if no errors.
func (*MultiTransport) PublishError ¶
func (tp *MultiTransport) PublishError(id string, network string, err error) error
func (*MultiTransport) RemoveTransport ¶
func (tp *MultiTransport) RemoveTransport(transport Transporter)
type MultiTransportError ¶
type MultiTransportError struct {
Errors []SingleTransportError
}
func (*MultiTransportError) Error ¶
func (err *MultiTransportError) Error() string
type MultiTransporter ¶
type MultiTransporter interface {
Transporter
AddTransport(transport Transporter)
RemoveTransport(transport Transporter)
}
type Networker ¶
type Networker interface {
io.Closer
Receiver
Logout(reason string) error // Same as Close() with logout reason.
Start(ctx context.Context, id string) error // id = request id
NetworkID() string
ConnID() string // empty if no connections.
Context() context.Context
Closed() bool
GetStateInfo() ClientStateInfo
}
Networker is a client implementation for a network.
type NewClientFunc ¶
type Service ¶
type Service struct {
Verbose bool // verbose output to log.Print/Printf
// contains filtered or unexported fields
}
Service is a service.
func NewService ¶
func NewService(tp Transporter, newClient NewClientFunc) *Service
NewService creates a new service. newClient must be set to a function, a lock will be acquired during newClient. The client eventually needs to call OnClientClosed when done.
func (*Service) CheckArgs ¶
CheckArgs ensures the CmdMsg has at least n args, if so returns true; otherwise returns false and publishes an error.
func (*Service) CmdHandler ¶
func (*Service) GenericError ¶
func (*Service) GetClientByNetwork ¶
func (*Service) GetClients ¶
func (*Service) GetStateInfo ¶
func (svc *Service) GetStateInfo() ServiceStateInfo
func (*Service) OnClientClosed ¶
OnClientClosed is to be called by the Client implementation when done. Panics if client.Closed() returns false.
func (*Service) Transporter ¶
func (svc *Service) Transporter() Transporter
type ServiceStateInfo ¶
type ServiceStateInfo struct {
Protocol stdchat.ProtocolStateInfo
Networks []stdchat.NetworkStateInfo
Subscriptions []stdchat.SubscriptionStateInfo
}
type Servicer ¶
type Servicer interface {
io.Closer
Receiver
GenericError(err error) // An error from outside, such as during msg dispatch.
GetClients() []Networker
GetClientByNetwork(networkID string) Networker
Protocol() string
Context() context.Context
Closed() bool
GetStateInfo() ServiceStateInfo
}
Servicer represents a service.
type SingleTransportError ¶
type SingleTransportError struct {
Transport Transporter
Err error
}
func (*SingleTransportError) Error ¶
func (err *SingleTransportError) Error() string
func (*SingleTransportError) Unwrap ¶
func (err *SingleTransportError) Unwrap() error
type Transporter ¶
type Transporter interface {
io.Closer
GetProtocol() string
// Advertise the service is up,
// this needs to be called before clients can do anything.
Advertise() error
// Publish a message.
// network and chat can be empty.
// node is the final part in the topic name, as in chat/Protocol/node
// e.g. to publish a protocol msg, use Publish("", "", "my-info", payload)
Publish(network, chat, node string, payload interface{}) error
// id should be the ID of the request (if a request), which can be empty.
// network can be empty if a protocol msg.
PublishError(id string, network string, err error) error
// Full URL returned.
// pathSuffix is the last part of the URL path, such as userA/foo4.png
// handler is set to a HTTP client handler to serve the headers+content.
// It is resonable that a directory is served.
// Use StopServeURL to stop serving.
ServeURL(network, pathSuffix string, handler http.Handler) (string, error)
// Cancel serving a URL.
// If this is the last served URL, the web service may shut down.
StopServeURL(network, pathSuffix string)
}
Transporter is a chat service transport.
type WebServer ¶
type WebServer struct {
PublicURL string // uses localhost and a random port if empty.
BindAddr string // parses from PublicURL if empty.
// contains filtered or unexported fields
}
func (*WebServer) ServeHTTP ¶
func (ws *WebServer) ServeHTTP(w http.ResponseWriter, r *http.Request)