Design
Scope
The deck pushes notifications to a Gotify™ server: push sends a title, a message and a priority, and pushExtras, pushMarkdown and pushWith add the two client hints most senders want (a markdown body, a URL opened on tap).
It is deliberately only the sending side of Gotify:
- No receiving. Reading messages over the websocket stream, listing or deleting messages, and managing applications, clients or users are client-token operations of a different kind of program.
- No other extras. Gotify's extras namespace is open-ended; the two that are supported are the ones Gotify's own clients act on for a notifier.
Decisions
- A deck, not a bundled module. A client for one vendor's service belongs in the deck ecosystem.
gotifyis the archetype of the bundled modules thatjennifermoves out (M30.1 in its milestones, formerly M28.32): the first one moved, and the sample the others followed. - Same surface as the module. The types and functions are those of the standard library's
gotifymodule, so migrating changes the import and addsallowInsecureHttptoConfigliterals (the module's literals may leave it out; a deck's may not). - No state. The caller holds a
Config(server URL and application token) and passes it to every call, so one program can push to several servers or applications without setup or teardown. - Form for plain pushes, JSON for extras.
pushposts the form-encoded body Gotify documents for its simplest use. Extras are a nested object, which a form cannot carry, so the extras calls post JSON. A zeroExtrassends noextraskey, and only the keys that are set reach the wire. - Plain HTTP is an explicit opt-in. The token is a credential, so
urlmust behttps://.http://to a loopback host (127.0.0.0/8,[::1],localhost) is allowed, since the request stays on the machine and tests need it; this matches the Slack™ and Discord™ decks. Self-hosted Gotify on a home network (an Unraid™ box, say) often speaks only HTTP, soConfig.allowInsecureHttpadmits plainhttp://to any host. It is a field ofConfigrather than a separate call, because the decision belongs to the server the config describes, and it defaults tofalse. The loopback test cuts the host out of the URL ashttpdoes (authority up to/,?or#, userinfo up to the last@), sohttp://127.0.0.1@evil.exampleis not loopback. - The token goes in a header. Gotify also accepts it as a
tokenquery parameter; theX-Gotify-Keyheader keeps it out of URLs, logs and proxies' access lines. - The response is returned, not judged. Every push returns the
http.Response. Gotify answers200; a wrong token is a401response. A notifier usually logs a failure and carries on, and a status is easier to log than a caught error.
Errors
The deck has no error struct (as recorded for the @jennifer decks in M28.57): the server's answer is the returned response. Its one throw is Error{kind: "gotify"} for a refused plain http:// URL, raised before any connection; the message leaves the URL out. Transport failures come from http unchanged: "timeout", "closed", "limit", and on interpreters with transport error kinds (M28.65) a net.NetError of kind "net" for a refused connection, reset, failed lookup or TLS failure (older ones throw those as "runtime").
Security and limits
- The application token is a credential. It lets anyone holding it push to that application. The docs and
examples/push.jread it from the environment (GOTIFY_TOKEN). - The token is never sent in the clear by default. A
urlother thanhttps://is refused unless it ishttp://to a loopback host orallowInsecureHttpis set. With the flag, the token and messages cross the network unencrypted, so it is for a trusted LAN only. The deck appends/messagetourland otherwise uses it as given. - Title, message and click URL are encoded (form or JSON), so they cannot change the request's structure. Priority is passed as given; Gotify decides what an out-of-range value means.
- Response size, deadlines and redirects are
http's defaults; the deck adds no caps of its own and no retries.
Testing and validation
src/gotify_test.j tests the form and JSON bodies directly (with and without each extra), the URL check (LAN http:// refused, loopback and https:// accepted, the opt-in, look-alike hosts such as 127.0.0.1.evil.example), and pushes through an httpd server on a loopback port that answers like Gotify: 200 with a message id for the right key, 401 otherwise. The test replaced the module's Go test when the module moved.
The tests never reach a real Gotify server. examples/push.j pushes when GOTIFY_URL and GOTIFY_TOKEN are set and posts nothing otherwise, so CI runs it offline.
Known limitations and open questions
- A trailing slash on
urlis not removed, so it yields//message. - The returned response is not decoded; a caller that wants the new message's id reads it from the body.
- No retries on a
5xxor a failed connection; a caller that needs delivery guarantees wraps the call.
Dependencies on the interpreter
- The floor is
>=0.27.0, for the UTF-8 codec ofencoding.decode; the bundled module is deprecated from 0.26.0 (M30.1). httpneeds thenetcapability, so pushing needs the defaultjenniferbinary; the stockjennifer-tinyhas no network driver.- Encoding uses the bundled
uri(encodeForm) andjsonmodules; the tests usehttpdandtaskfor the loopback server.