fb61e72e06
- cmd/frontend/web: honour ?instance=<hostname> query parameter on the initial scope hydration so /view/?instance=lb-ams opens the dashboard scoped to that maglevd. The cookie is updated on consumption; an unknown name still falls back to the first server via App.tsx. - cmd/client, cmd/frontend: --server now accepts bare hostnames. A new internal/netutil.EnsurePort canonicalises addresses by appending :9090 when no port is given, with bracketing for bare IPv6 literals. Unit test covers the IPv4/IPv6/bracketed/already-ported permutations. - Makefile: new self-documenting `help` target as the default rule; every user-facing target now carries a `## ` description that the awk-based help auto-extracts. fixstyle-web skips with a friendly message when prettier isn't installed instead of failing on npx. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package netutil holds tiny networking helpers shared across cmd/
|
|
// binaries. Kept deliberately minimal — anything more involved than a
|
|
// few lines belongs in its own package.
|
|
package netutil
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
// EnsurePort returns addr unchanged when it already carries a port, or
|
|
// addr with ":<defaultPort>" appended otherwise. Bare IPv6 literals
|
|
// ("2001:db8::1", "::1") are bracketed so the result is valid input to
|
|
// grpc.NewClient and net.Dial. An empty addr is returned unchanged.
|
|
func EnsurePort(addr, defaultPort string) string {
|
|
if addr == "" {
|
|
return addr
|
|
}
|
|
if _, _, err := net.SplitHostPort(addr); err == nil {
|
|
return addr
|
|
}
|
|
// Already-bracketed bare IPv6 ("[::1]") falls through to the plain
|
|
// concat at the bottom. Unbracketed IPv6 needs brackets first; we
|
|
// detect it by handing the literal to net.ParseIP, which only
|
|
// accepts the bare form (no brackets, no port).
|
|
if ip := net.ParseIP(addr); ip != nil && ip.To4() == nil && strings.Contains(addr, ":") {
|
|
return "[" + addr + "]:" + defaultPort
|
|
}
|
|
return addr + ":" + defaultPort
|
|
}
|