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 <danderson@tailscale.com>
maisem/doc
David Anderson 1 year ago committed by Dave Anderson
parent 5ebb271322
commit ed46442cb1

@ -10,6 +10,7 @@ import "tailscale.com/tailcfg"
const LocalAPIHost = "local-tailscaled.sock" const LocalAPIHost = "local-tailscaled.sock"
// WhoIsResponse is the JSON type returned by tailscaled debug server's /whois?ip=$IP handler. // 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 { type WhoIsResponse struct {
Node *tailcfg.Node Node *tailcfg.Node
UserProfile *tailcfg.UserProfile UserProfile *tailcfg.UserProfile

@ -427,8 +427,8 @@ func (h *Handler) serveWhoIs(w http.ResponseWriter, r *http.Request) {
return return
} }
res := &apitype.WhoIsResponse{ res := &apitype.WhoIsResponse{
Node: n, Node: n, // always non-nil per WhoIsResponse contract
UserProfile: &u, UserProfile: &u, // always non-nil per WhoIsResponse contract
CapMap: b.PeerCaps(ipp.Addr()), CapMap: b.PeerCaps(ipp.Addr()),
} }
j, err := json.MarshalIndent(res, "", "\t") j, err := json.MarshalIndent(res, "", "\t")

Loading…
Cancel
Save