Documentation
¶
Overview ¶
Package listen runs the listen commands of webhooks and routes: it connects to the AhaSend event stream, prints each event and forwards it, signed, to a local endpoint.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddListenFlags ¶
AddListenFlags adds the --forward-to, --skip-verify and --slim-output flags of a listen command.
func Listen ¶
Listen connects to the stream of l, prints its banner and then every event until the user interrupts or the server closes the connection, forwarding each event to l.ForwardTo, signed with a secret it generates, when set. An interruption while connecting ends the command too, with no error. When stdout cannot be written, as when it is a pipe whose reader exited, the stream ends and Listen returns the write error.
When l.DeleteTemporary is set, Listen deletes the temporary webhook or route last, however the stream ended, as deleteTemporary describes. The delete does not change the error Listen returns.
func ReadForwardTo ¶
ReadForwardTo returns the --forward-to URL of a listen command, or "" when it is empty. A value that is not an HTTP or HTTPS URL, a URL with a user name or password, which the banner and logs would show, and --skip-verify without --forward-to are validation errors, and a URL that sends events over plain HTTP to another host gets the warning of WarnIfInsecureURL, which names what is forwarded with sent. It runs once every other input is valid.
Types ¶
type Listener ¶
type Listener struct {
// Kind names the stream in messages, such as "webhook" or "route".
Kind string
// Title starts the connection banner, such as "Webhook".
Title string
// ID is the ID of the webhook or route the stream belongs to.
ID string
// WsURL is the websocket URL the stream API returned.
WsURL string
// Waiting names what the command listens for, such as "events".
Waiting string
// Details prints connection details after the ID line; nil prints none.
Details func(out io.Writer)
// DeleteTemporary deletes the temporary webhook or route the API created
// for the stream; nil when the stream belongs to an existing one.
DeleteTemporary func() error
// Keep reports whether to show and forward an event of eventType; nil
// keeps every event.
Keep func(eventType string) bool
// SlimDetails prints what a slim event line shows after the event type;
// nil prints only the type. It passes every value from data through
// printer.EscapeControl, since the stream's events carry text from email senders.
SlimDetails func(out io.Writer, data map[string]interface{})
ForwardTo string
// SkipVerify skips TLS certificate verification when forwarding to
// ForwardTo; the AhaSend stream is always verified.
SkipVerify bool
SlimOutput bool
}
Listener describes the stream a listen command shows and forwards.