hubclient

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 7 Imported by: 0

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

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 NewFake

func NewFake() *Fake

NewFake constructs a Fake.

func (*Fake) Inject

func (f *Fake) Inject(channel string, fr Frame)

Inject pushes a frame to a channel's subscriber as if it arrived from the hub.

func (*Fake) MintChannel

func (f *Fake) MintChannel(ctx context.Context) (string, error)

MintChannel returns a unique fake channel id.

func (*Fake) Publish

func (f *Fake) Publish(ctx context.Context, channel, body string) error

Publish records a publish and forwards it to any subscriber of `channel`.

func (*Fake) Published

func (f *Fake) Published(channel string) []string

Published returns the bodies published to a channel (test helper).

func (*Fake) Subscribe

func (f *Fake) Subscribe(ctx context.Context, channel, resume string) (<-chan Frame, error)

Subscribe returns a buffered channel that Publish feeds.

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

func (c *HTTPClient) Subscribe(ctx context.Context, channel, resume string) (<-chan Frame, error)

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.

type HubClient

type HubClient interface {
	MintChannel(ctx context.Context) (string, error)
	Publish(ctx context.Context, channel, body string) error
	Subscribe(ctx context.Context, channel, resume string) (<-chan Frame, error)
}

HubClient is the hub surface the router depends on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL