listen

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func AddListenFlags(cmd *cobra.Command)

AddListenFlags adds the --forward-to, --skip-verify and --slim-output flags of a listen command.

func Listen

func Listen(cmd *cobra.Command, apiClient client.AhaSendClient, l Listener) error

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

func ReadForwardTo(cmd *cobra.Command, sent string) (string, error)

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.

Jump to

Keyboard shortcuts

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