Documentation ¶
Overview ¶
Package bridge defines the bridge struct, which implements the control loop and functions of the GCS's bridge client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnknownMessage ¶ added in v0.3.9
func UnknownMessage(w ResponseWriter, r *Request)
UnknownMessage represents the default handler logic for an unmatched request type sent from the bridge.
Types ¶
type Bridge ¶ added in v0.3.3
type Bridge struct { // Handler to invoke when messages are received. Handler Handler // contains filtered or unexported fields }
Bridge defines the bridge client in the GCS. It acts in many ways analogous to go's `http` package and multiplexer.
It has two fundamentally different dispatch options:
- Request/Response where using the `Handler` a request of a given type will be dispatched to the apprpriate handler and an appropriate `ResponseWriter` will respond to exactly that request that caused the dispatch.
- `PublishNotification` where a notification that was not initiated by a request from any client can be written to the bridge at any time in any order.
func (*Bridge) AssignHandlers ¶ added in v0.3.3
AssignHandlers creates and assigns the appropriate bridge events to be listen for and intercepted on `mux` before forwarding to `gcs` for handling.
func (*Bridge) ListenAndServe ¶ added in v0.3.3
func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser) error
ListenAndServe connects to the bridge transport, listens for messages and dispatches the appropriate handlers to handle each event in an asynchronous manner.
func (*Bridge) PublishNotification ¶ added in v0.3.3
func (b *Bridge) PublishNotification(n *prot.ContainerNotification)
PublishNotification writes a specific notification to the bridge.
type Handler ¶ added in v0.3.3
type Handler interface {
ServeMsg(ResponseWriter, *Request)
}
Handler responds to a bridge request.
func UnknownMessageHandler ¶ added in v0.3.9
func UnknownMessageHandler() Handler
UnknownMessageHandler creates a default HandlerFunc out of the UnknownMessage handler logic.
type HandlerFunc ¶ added in v0.3.3
type HandlerFunc func(ResponseWriter, *Request)
HandlerFunc is an adapter to use functions as handlers.
func (HandlerFunc) ServeMsg ¶ added in v0.3.3
func (f HandlerFunc) ServeMsg(w ResponseWriter, r *Request)
ServeMsg calls f(w, r).
type Mux ¶ added in v0.3.3
type Mux struct {
// contains filtered or unexported fields
}
Mux is a protocol multiplexer for request response pairs following the bridge protocol.
func NewBridgeMux ¶ added in v0.3.3
func NewBridgeMux() *Mux
NewBridgeMux creates a default bridge multiplexer.
func (*Mux) Handle ¶ added in v0.3.3
func (mux *Mux) Handle(id prot.MessageIdentifier, ver prot.ProtocolVersion, handler Handler)
Handle registers the handler for the given message id and protocol version.
func (*Mux) HandleFunc ¶ added in v0.3.3
func (mux *Mux) HandleFunc(id prot.MessageIdentifier, ver prot.ProtocolVersion, handler func(ResponseWriter, *Request))
HandleFunc registers the handler function for the given message id and protocol version.
func (*Mux) Handler ¶ added in v0.3.3
Handler returns the handler to use for the given request type.
func (*Mux) ServeMsg ¶ added in v0.3.3
func (mux *Mux) ServeMsg(w ResponseWriter, r *Request)
ServeMsg dispatches the request to the handler whose type matches the request type.
type Request ¶ added in v0.3.3
type Request struct { Header *prot.MessageHeader Message []byte Version prot.ProtocolVersion }
Request is the bridge request that has been sent.
type ResponseWriter ¶ added in v0.3.3
type ResponseWriter interface { // Header is the request header that was requested. Header() *prot.MessageHeader // Write a successful response message. Write(interface{}) // Error writes the provided error as a response to the message correlated // with the activity ID passed. If the activity ID is the empty string it // will be translated to an empty guid. Error(string, error) }
ResponseWriter is the dispatcher used to construct the Bridge response.