Documentation
¶
Overview ¶
Package bridgeapi is the bridge half of go-fabric-server: the /bridge API through which a host that is not written in Go declares devices, sends state deltas and answers what a controller asks of them (concept v8 C.3, brief S2 §1).
The half maps go-fabric's device kit one-to-one: a declaration is device.New with each cluster's generated <cluster>def.Declare, its initial state decoded into the generated Patch (clusters_gen.go, written by internal/gen from the snapshot's cluster list, holds one kit per typed package); the whole document is one Aggregator.Batch. set is the typed Server.Set, host is Device.Update, SetReachable and Rename. A change the host did not make is the changed event; a write or a command reaches the host as a write or command event only when the declaration opted in (OnWrite, Handle<Command>), with a correlation and a deadline.
Lifecycle: New → wire Server.Observers into node.Config.Observers → node.New and Start → Server.Start with the node → serve Server.ServeHTTP at /bridge → Server.Shutdown → stop the node. One bridge client at a time.
Index ¶
Constants ¶
const ( ExtensionsFlag = "--bridge-extensions" SpecLevelFlag = "--bridge-spec-level" )
ExtensionsFlag and SpecLevelFlag are the daemon flags that set the node's surface policies the refusals name: the enabled "Ahead of matter.js" register IDs (surface.Policies.Extensions) and the specification level (surface.Policies.Level).
const BridgeSchemaVersion = 1
BridgeSchemaVersion is the schema number of the bridge half, apart from the controller half's (concept v8 C.1).
const StatusBusy websocket.StatusCode = 4409
StatusBusy is the WebSocket close status of a second bridge client: the daemon's node has one author (brief S2 §1.1).
Variables ¶
This section is empty.
Functions ¶
func Capabilities ¶
func Capabilities() []string
Capabilities are the commands of the bridge half, sorted.
Types ¶
type Options ¶
type Options struct {
// Version is go-fabric-server's version, GoFabricVersion go-fabric's,
// for server_info's sdk_version.
Version, GoFabricVersion string
// ResultTimeout is how long a write or command event waits for its
// result; 0 is 5 seconds.
ResultTimeout time.Duration
// SubscriptionPoll is how often the node's subscription count is
// read for the subscriptions event; 0 is 5 seconds.
SubscriptionPoll time.Duration
// Logger receives the server's logs; nil discards them.
Logger *slog.Logger
// Metrics receives the send path's metrics.
Metrics protocol.Metrics
// Conn overrides the backpressure defaults of the connection (tests).
Conn protocol.ConnOptions
// MaxInFlight bounds the requests the client runs at once; 0 is 64.
MaxInFlight int
// Surface are the surface policies of the node the server binds to:
// the node's node.Config.Surface, the same value. Every declared
// device is built under them (device.Options.Surface), since the
// node's Aggregator refuses a device composed under other policies
// (go-fabric node.ErrPolicyMismatch). The zero value is no policy.
Surface surface.Policies
// Node is the key of the device node the server binds to, as the
// daemon names it (its registry key, "default" for the --bridge-*
// node); server_info reports it as node, so a client sees
// which node it feeds. Empty reports "default".
Node string
}
Options configures a Server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the bridge half. Its methods are safe for concurrent use.
func (*Server) Health ¶
Health is the bridge half's state for GET /health: healthy once started and until shut down; devices is the declared device count.
func (*Server) Observers ¶
Observers are the node observers the server needs for its fabric_added, fabric_removed and commissioning_window events: wire them as node.Config.Observers before node.New.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves the bridge client's WebSocket. A second client while one is connected receives an error frame naming the holder and the close status StatusBusy.