Documentation
¶
Overview ¶
Package mercure is the scriptling.mercure library: a client for Mercure hubs (https://mercure.rocks). A script publishes updates to topics and subscribes to them over Server-Sent Events, against any Mercure hub: the reference hub, FrankenPHP's built-in one, or a gossiper cluster.
It speaks Mercure 1.0 by default: create_token makes access tokens bound to the hub, and subscribe takes exact topics and URL patterns. Draft-07 (the mercure claim and URI templates) is there for hubs that take only that: create_token(draft07=True) and subscribe(topics=...).
It is built on gossiper's Go client. By default each publish is a POST of its own, as Mercure's HTTP protocol has it, which every hub takes. With stream=True a client publishes to a gossiper hub over one long streaming request instead, many times faster for a script that publishes a lot. Subscriptions reconnect by themselves and resume from their last event ID.
Index ¶
Constants ¶
const ( LibraryName = "scriptling.mercure" LibraryDesc = "Mercure hub client: publish updates and subscribe to topics over Server-Sent Events" )
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(registrar interface{ RegisterLibrary(*object.Library) }, cfg ...*netsecurity.Config)
Register registers scriptling.mercure, under the network policy cfg when one is given. A CA bundle a script names with verify="path" may be any file: use RegisterConfigured to confine it.
func RegisterConfigured ¶
func RegisterConfigured(registrar interface{ RegisterLibrary(*object.Library) }, paths fssecurity.Config, policy *netsecurity.Config, opts ...Option)
RegisterConfigured registers scriptling.mercure with a filesystem allow-path policy and a network policy, as the CLI's --allowed-paths and --network-policy give them: every connection to a hub passes the network policy, and a CA bundle named with verify="path" must lie within the allowed paths. A zero fssecurity.Config and a nil policy register it unrestricted.
Clients live until the script closes them, or until a runtime reset; give WithLifetime to close them when an environment is done with as well.
Types ¶
type Option ¶
type Option func(*transports)
Option configures the library.
func WithLifetime ¶
WithLifetime bounds the clients scripts make through this registration: lifetime is called as each client is made, and the client and its subscriptions are closed when the context it returns ends. It is for an embedder that throws an environment away, or lends it to another user, after a script: a subscription the script left open goes with it. A client made after that context has ended fails.