Help us shape the future of Go! Take the 2026 Go Developer Survey

netaddr

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package netaddr resolves which host/IP the review server should bind to and which alternate URLs to advertise, with first-class support for Tailscale tailnets so a remote box is reachable from the user's phone without exposing the diff on a public interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AltURLs

func AltURLs(bindHost, tsIP, magicDNS string, port int) []string

AltURLs returns *additional* reachable URLs to advertise alongside the canonical READY line — never including the bind URL itself (the caller already prints that). The MagicDNS hostname is the headline extra: on a phone, tapping `http://box.tailnet.ts.net:PORT` beats typing a 100.x.y.z octet string. Order is stable and the bound form is de-duplicated out so the user never sees the same endpoint twice.

func IsRemoteBox

func IsRemoteBox() bool

IsRemoteBox reports whether prereview is running on a machine the user is connected to over the network rather than sitting in front of. An active SSH session is the canonical, dependency-free signal: any of the three vars is set by sshd for the session's processes.

This gates the auto-rebind: on a local dev box (no SSH) we keep the historical 127.0.0.1 default so nothing about the laptop workflow changes, even if that laptop happens to be on a tailnet.

func ResolveBindHost

func ResolveBindHost(explicitHost bool, host string, remote bool, tsIP string) (bindHost string, warn string)

ResolveBindHost decides which host/IP the server should bind to, given the situation. It returns the bind host plus an optional human warning (printed to stderr by the caller; "" means nothing to say).

=== The contract this MUST satisfy (see netaddr_test.go) ===

explicitHost == true
    → host, ""            (the operator's --host is absolute,
                           even if it's 0.0.0.0 — their call)
!explicitHost && remote && tsIP != ""
    → tsIP, ""            (the whole point: reachable over the
                           tailnet, never the public internet)
!explicitHost && remote && tsIP == ""
    → "127.0.0.1", <warn> (remote but NO tailnet — loopback is
                           unreachable from the user's phone;
                           the warning must tell them so AND how
                           to fix it, e.g. mention --host)
!explicitHost && !remote
    → "127.0.0.1", ""     (local dev — unchanged historical default)

Parameters:

explicitHost — did the operator actually pass --host on the CLI?
host         — the value of --host (its flag default is "127.0.0.1")
remote       — IsRemoteBox()
tsIP         — TailscaleIPv4()'s ip ("" when there's no tailnet)

───────────────────────────────────────────────────────────────────── TODO(you): implement this. ~5–10 lines. The four happy/edge rows above are the spec; netaddr_test.go pins them as a table. The judgment call is the third row — remote with no tailnet: we fall back to loopback (per the chosen policy) but the *warning text* is the difference between a user who's stuck and one who knows to pass --host. Make that message count; it's the only feedback they'll get before they go looking for a URL that isn't reachable. ─────────────────────────────────────────────────────────────────────

func TailscaleIPv4

func TailscaleIPv4() (ip string, magicDNS string)

TailscaleIPv4 returns this host's Tailscale IPv4 address and, when discoverable, its MagicDNS hostname (trailing dot stripped). Either may be empty:

  • ip == "" → no tailnet interface on this host
  • magicDNS == "" → on a tailnet, but the `tailscale` CLI wasn't available to resolve the friendly name; the IP still works

The IP comes from pure interface enumeration (always works, headless, testable). The MagicDNS name is a best-effort nicety shelled out to `tailscale status --json` — any failure there is swallowed, never fatal: a working 100.x URL beats a missing one.

Types

This section is empty.

Jump to

Keyboard shortcuts

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