From ed46442cb1200a74883b91657b2e4ab0d62cdc22 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 31 Jul 2023 09:25:39 -0700 Subject: [PATCH] client/tailscale/apitype: document never-nil property of WhoIsResponse Every time I use WhoIsResponse I end up writing mildly irritating nil-checking for both Node and UserProfile, but it turns out our code guarantees that both are non-nil in successful whois responses. Updates #cleanup Signed-off-by: David Anderson --- client/tailscale/apitype/apitype.go | 1 + ipn/localapi/localapi.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/tailscale/apitype/apitype.go b/client/tailscale/apitype/apitype.go index c3dbd5a78..b63abf69c 100644 --- a/client/tailscale/apitype/apitype.go +++ b/client/tailscale/apitype/apitype.go @@ -10,6 +10,7 @@ import "tailscale.com/tailcfg" const LocalAPIHost = "local-tailscaled.sock" // WhoIsResponse is the JSON type returned by tailscaled debug server's /whois?ip=$IP handler. +// In successful whois responses, Node and UserProfile are never nil. type WhoIsResponse struct { Node *tailcfg.Node UserProfile *tailcfg.UserProfile diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index e2fe3b6bc..36b8cbf16 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -427,8 +427,8 @@ func (h *Handler) serveWhoIs(w http.ResponseWriter, r *http.Request) { return } res := &apitype.WhoIsResponse{ - Node: n, - UserProfile: &u, + Node: n, // always non-nil per WhoIsResponse contract + UserProfile: &u, // always non-nil per WhoIsResponse contract CapMap: b.PeerCaps(ipp.Addr()), } j, err := json.MarshalIndent(res, "", "\t")