Documentation
¶
Overview ¶
Package zapweb serves ZAP procedures over WebSocket so browser clients — which cannot open a raw TCP/QUIC socket — reach the EXACT same zapclient.Server procedure dispatch as native in-cluster peers.
One dispatch path, two transports:
- native ZAP (TCP/QUIC), via zap.Node, for service-to-service calls
- zapweb (WebSocket), via this package, for browser ↔ service calls
There is no REST here. The WebSocket handshake is an HTTP/1.1 Upgrade; everything after it is binary ZAP frames, dispatched through zapclient.Server.Dispatch (the same opcode routing + PeerVerifier the native node uses).
Wire format (one WebSocket BINARY message per call) ¶
[ reqID uint32 LE ] correlation id — echoed on the reply
[ flag uint32 LE ] zap.ReqFlagReq on request, zap.ReqFlagResp on
reply, FlagErr on a dispatch-level failure
[ zap.Message bytes ] the procedure message; its Flags() header
carries the procedure opcode, identical to the
native transport. On a FlagErr reply the tail
is a UTF-8 error string instead.
The JS/TS client builds byte-identical frames (see zapweb/ts), so the browser and a Go caller speak the same protocol to the same handlers.
Index ¶
Constants ¶
const FlagErr uint32 = 3
FlagErr marks a reply whose tail is a UTF-8 error string rather than a ZAP message — used when Dispatch itself fails (unknown procedure, rejected peer, handler error). Distinct from zap.ReqFlagReq(1) / zap.ReqFlagResp(2).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a zapweb (ZAP-over-WebSocket) client. Construct with Dial, always Close.
func Dial ¶
Dial opens a zapweb connection to url (e.g. "ws://host:port/zap" or "wss://..."). Caller MUST Close.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, procedure string, req *zap.Message) (*zap.Message, error)
Call invokes procedure with req and returns the reply message. req may be nil for parameter-less procedures. A dispatch-level failure on the server (unknown procedure / rejected peer / handler error) is returned as a Go error; procedure-level status lives inside the reply message (same as the native transport).
type Options ¶
type Options struct {
// OriginPatterns is the WebSocket Origin allowlist (coder/websocket
// AcceptOptions.OriginPatterns). Empty means same-origin only — set
// the SPA hosts explicitly for cross-origin browser access.
OriginPatterns []string
// PeerID is the identity handed to the server's PeerVerifier for
// browser calls. Default "zapweb". Authentication of the browser
// principal rides in the procedure payload (bearer/JWT) or a TLS
// client cert at the ingress, not in this field.
PeerID string
// MaxMessage caps a single inbound message in bytes. Default 1 MiB.
MaxMessage int64
}
Options configure Handler.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
echoserver
command
Command echoserver runs a zapweb (ZAP-over-WebSocket) echo service for cross-language integration testing.
|
Command echoserver runs a zapweb (ZAP-over-WebSocket) echo service for cross-language integration testing. |