Documentation ¶
Index ¶
- Constants
- type Action
- type ActionMap
- type CallMessage
- type ResultMessage
- type Signal
- type SignalMessage
- type Sockets
- func (sockets *Sockets) Actions() ActionMap
- func (sockets *Sockets) Generic(scope component.Scope, scopeParam string, numParams int, ...) Action
- func (sockets *Sockets) HandleRoute(ctx context.Context, path string) (http.Handler, error)
- func (sockets *Sockets) Instance(scope component.Scope, scopeParam string, numParams int, ...) Action
- func (socket *Sockets) Routes() component.Routes
- func (socket *Sockets) Serve(conn httpx.WebSocketConnection)
- type WriteFunc
Constants ¶
const (
SignalCancel = "cancel"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { // NumPara NumParams int // Scope and ScopeParam indicate the scope required by the caller. // TODO(twiesing): Once we actually include scopes, make them dynamic Scope component.Scope ScopeParam string // Handle handles this action. // // ctx is closed once the underlying connection is closed. // out is an io.Writer that is automatically sent to the client. // params holds exactly NumParams parameters. Handle func(ctx context.Context, in io.Reader, out io.Writer, params ...string) error }
Action is something that can be handled via a WebSocket connection.
type ActionMap ¶
ActionMap handles a set of WebSocket actions
func (ActionMap) Handle ¶
func (am ActionMap) Handle(auth *auth.Auth, conn httpx.WebSocketConnection) (name string, err error)
Handle handles a new incoming websocket connection using the given authentication.
There are two kinds of messages:
- text messages, which are used to send input and output. - binary messages, which are json-encoded and used for control flow.
To call an action, a client should send a CallMessage struct. The server will then start handling input and output (via text messages). If the client sends a SignalMessage, the signal is propagnated to the underlying context. Finally it will send a ResultMessage once handling is complete.
A corresponding client implementation of this can be found in ..../remote/proto.ts
type CallMessage ¶
CallMessage is sent by the client to the server to invoke a remote procedure
type ResultMessage ¶
type ResultMessage struct { Success bool `json:"success"` Message string `json:"message,omitempty"` }
ResultMessage is sent by the server to the client to report the success of a remote procedure
type SignalMessage ¶
type SignalMessage struct {
Signal Signal `json:"signal"`
}
CancelMessage is sent from the client to the server to stop the current procedure
type Sockets ¶
type Sockets struct { component.Base Dependencies struct { Provision *provision.Provision Instances *instances.Instances Exporter *exporter.Exporter Purger *purger.Purger Auth *auth.Auth } // contains filtered or unexported fields }
func (*Sockets) Generic ¶
func (sockets *Sockets) Generic(scope component.Scope, scopeParam string, numParams int, handler func(ctx context.Context, socket *Sockets, in io.Reader, out io.Writer, params ...string) error) Action
Generic returns a new action that calls handler with the provided number of parameters
func (*Sockets) HandleRoute ¶
func (*Sockets) Instance ¶
func (sockets *Sockets) Instance(scope component.Scope, scopeParam string, numParams int, handler func(ctx context.Context, sockets *Sockets, instance *wisski.WissKI, in io.Reader, out io.Writer, params ...string) error) Action
Insstance returns a new action that calls handler with a specific WissKI instance
func (*Sockets) Serve ¶
func (socket *Sockets) Serve(conn httpx.WebSocketConnection)
Serve handles a connection to the websocket api