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)
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.
A client and its subscriptions live until the script closes them, or until the interpreter that made it closes what its scripts left open (Reset, ResetEnv, Close), or once the script no longer holds the client.
Types ¶
This section is empty.