Documentation
¶
Overview ¶
Package hubclient abstracts the botbus hub's public HTTP surface (mint, publish, subscribe-with-resume) so the router never imports hub internals.
Index ¶
- type Fake
- func (f *Fake) Inject(channel string, fr Frame)
- func (f *Fake) MintChannel(ctx context.Context) (string, error)
- func (f *Fake) Publish(ctx context.Context, channel, body string) error
- func (f *Fake) Published(channel string) []string
- func (f *Fake) Subscribe(ctx context.Context, channel, resume string) (<-chan Frame, error)
- type Frame
- type HTTPClient
- type HubClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is an in-memory HubClient for tests.
func (*Fake) Inject ¶
Inject pushes a frame to a channel's subscriber as if it arrived from the hub.
func (*Fake) MintChannel ¶
MintChannel returns a unique fake channel id.
type Frame ¶
type Frame struct {
Name string // sender name (left of "name: body")
Body string // message body
Resume string // resume token to persist (the SSE id: field)
}
Frame is one received message from a subscribed channel.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient talks to a real botbus hub over HTTP/SSE.
func NewHTTPClient ¶
func NewHTTPClient(base, domain string) *HTTPClient
NewHTTPClient constructs an HTTPClient. base is the dialable origin; domain is the apex used to build the `<channel>.<domain>` Host header the hub routes on.
func (*HTTPClient) MintChannel ¶
func (c *HTTPClient) MintChannel(ctx context.Context) (string, error)
MintChannel GETs the hub mint endpoint (new.<domain>) and returns the id.
The real hub (servNew in ui.go) responds with a full channel URL plus a trailing newline — "https://<id>.<domain>/\n" — NOT a bare id, so we strip the scheme, the "."+domain suffix, and the trailing slash to recover the id (mirroring the hub's own e2eMint test helper).
func (*HTTPClient) Publish ¶
func (c *HTTPClient) Publish(ctx context.Context, channel, body string) error
Publish POSTs `body` to the channel (Host-header addressed). The hub replies 204 No Content on success (servPublish in transport.go).
func (*HTTPClient) Subscribe ¶
Subscribe opens an SSE stream and parses frames until ctx is cancelled. The hub addresses channels by Host subdomain, gates SSE on Accept: text/event-stream, and resumes gap-only from the Last-Event-ID header (see servSSE in transport.go). Each event is `id: <token>\n` then one-or-more `data: <line>\n` then a blank line.