Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterHTTP ¶
func RegisterHTTP(route string, handler HTTPHandler)
func Route ¶
func Route(route string, handler MsgHandler)
Route registers a handler for a specified route. The handler map is global and has no mutex protection. All calls to Route should be done before the Server is started.
Types ¶
type HTTPHandler ¶
type HTTPHandler func(thing interface{}) (interface{}, error)
HTTPHandler describes a handler for an HTTP route.
type Link ¶
type Link interface {
// Done returns a channel that is closed when the link goes down.
Done() <-chan struct{}
// ID returns a unique ID by which this connection can be identified.
ID() uint64
// Addr returns the string-encoded IP address.
Addr() string
// Send sends the msgjson.Message to the peer.
Send(msg *msgjson.Message) error
// SendError sends the msgjson.Error to the peer, with reference to a
// request message ID.
SendError(id uint64, rpcErr *msgjson.Error)
// Request sends the Request-type msgjson.Message to the client and registers
// a handler for the response.
Request(msg *msgjson.Message, f func(Link, *msgjson.Message), expireTime time.Duration, expire func()) error
// Banish closes the link and quarantines the client.
Banish()
// Disconnect closes the link.
Disconnect()
// Authorized should be called from a request handler when the connection
// becomes authorized. Request handlers must be run synchronous with other
// reads or it will be a data race with the link's input loop.
Authorized()
}
Link is an interface for a communication channel with an API client. The reference implementation of a Link-satisfying type is the wsLink, which passes messages over a websocket connection.
type MsgHandler ¶
MsgHandler describes a handler for a specific message route.
func RouteHandler ¶
func RouteHandler(route string) MsgHandler
RouteHandler gets the handler registered to the specified route, if it exists.
type RPCConfig ¶
type RPCConfig struct {
// ListenAddrs are the addresses on which the server will listen.
ListenAddrs []string
// The location of the TLS keypair files. If they are not already at the
// specified location, a keypair with a self-signed certificate will be
// generated and saved to these locations.
RPCKey string
RPCCert string
// AltDNSNames specifies allowable request addresses for an auto-generated
// TLS keypair. Changing AltDNSNames does not force the keypair to be
// regenerated. To regenerate, delete or move the old files.
AltDNSNames []string
// DisableDataAPI will disable all traffic to the HTTP data API routes.
DisableDataAPI bool
}
The RPCConfig is the server configuration settings and the only argument to the server's constructor.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a low-level communications hub. It supports websocket clients and an HTTP API.
func NewServer ¶
A constructor for an Server. The Server handles a map of clients, each with at least 3 goroutines for communications. The server is TLS-only, and will generate a key pair with a self-signed certificate if one is not provided as part of the RPCConfig. The server also maintains a IP-based quarantine to short-circuit to an error response for misbehaving clients, if necessary.
func (*Server) Broadcast ¶
Broadcast sends a message to all connected clients. The message should be a notification. See msgjson.NewNotification.
func (*Server) EnableDataAPI ¶
EnableDataAPI enables or disables the HTTP data API endpoints.