Documentation
¶
Overview ¶
Package hostutil provides shared utilities for host URL handling.
Index ¶
- func ApplyLayout(ctx context.Context, mux Multiplexer, layout string) error
- func CurrentPaneCommands(ctx context.Context, mux Multiplexer) ([]string, error)
- func HeadlessReason() string
- func IsLocalhost(host string) bool
- func IsRemoteSession() bool
- func IsTrustedBasecampHost(rawURL, cfgBaseURL string) bool
- func Normalize(host string) string
- func OpenBrowser(url string) error
- func RequireSecureURL(rawURL string) error
- func SplitPane(ctx context.Context, mux Multiplexer, exe string, args ...string) error
- type Multiplexer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyLayout ¶ added in v0.3.0
func ApplyLayout(ctx context.Context, mux Multiplexer, layout string) error
ApplyLayout sets the multiplexer pane layout.
func CurrentPaneCommands ¶ added in v0.3.0
func CurrentPaneCommands(ctx context.Context, mux Multiplexer) ([]string, error)
CurrentPaneCommands returns the commands running in each pane (tmux only).
func HeadlessReason ¶ added in v0.12.0
func HeadlessReason() string
HeadlessReason reports why this host cannot show a browser to the person at the terminal, or "" when launching one is worth trying. It is the browser-launch half of session detection: IsRemoteSession decides whether a loopback callback can be reached at all, this decides whether `open` / `xdg-open` would land anywhere the user can see. The reason is written for a terminal line ("Not opening a browser here (SSH session)").
Only environment is consulted, so the answer is cheap and deterministic: an SSH session (any of the three variables sshd sets), a CI runner (the CI variable every major provider exports), or a Unix host with neither an X11 nor a Wayland display. macOS and Windows have no display variable to check; a GUI-less session there is rare enough to leave to the launch error path.
func IsLocalhost ¶
IsLocalhost returns true if host is localhost, a .localhost subdomain, 127.0.0.1, or [::1] (with optional port).
func IsRemoteSession ¶ added in v0.3.0
func IsRemoteSession() bool
IsRemoteSession returns true when running inside an SSH session, detected via SSH_CONNECTION, SSH_CLIENT, or SSH_TTY environment variables.
func IsTrustedBasecampHost ¶ added in v0.8.0
IsTrustedBasecampHost reports whether rawURL points at a host the CLI trusts for resolving Basecamp resource URLs. Trusted hosts are the production Basecamp 3 domains, any localhost host (covers *.localhost dev domains), and the host of the configured base URL (covers custom/staging deployments and http://3.basecamp.localhost:3001-style local dev). Everything else is rejected so a look-alike URL on an attacker-controlled host — which the host-agnostic URL router would otherwise parse — cannot be trusted into a mutating request. cfgBaseURL may be empty.
func Normalize ¶
Normalize converts a host string to a full URL. - Empty string returns empty - localhost/127.0.0.1 defaults to http:// - Other bare hostnames default to https:// - Full URLs are used as-is
func OpenBrowser ¶
OpenBrowser opens the specified URL in the default browser.
func RequireSecureURL ¶ added in v0.2.0
RequireSecureURL returns an error if the URL uses http:// for a non-localhost host. Localhost (127.0.0.1, ::1, *.localhost) is exempt for local development.
Types ¶
type Multiplexer ¶ added in v0.3.0
type Multiplexer string
Multiplexer identifies a detected terminal multiplexer.
const ( MultiplexerNone Multiplexer = "" MultiplexerTmux Multiplexer = "tmux" MultiplexerZellij Multiplexer = "zellij" )
func DetectMultiplexer ¶ added in v0.3.0
func DetectMultiplexer() Multiplexer
DetectMultiplexer returns the active terminal multiplexer, if any.