From 613d624bea9b48d3d15deefda18c8d0e6dcbbf8e Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 17 Oct 2022 13:43:46 -0400 Subject: [PATCH] tsnet/examples/tshello: update example for LocalClient method (#5966) Before this would silently fail if this program was running on a machine that was not already running Tailscale. This patch changes the WhoIs call to use the tsnet.Server LocalClient instead of the global tailscale LocalClient. Signed-off-by: Xe Change-Id: Ieb830fbce81292acc4c3b4d1b675aa10766a18dc Signed-off-by: Xe (cherry picked from commit 86c5bddce20a98eb8f37de96bd08417bc594083e) --- tsnet/example/tshello/tshello.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tsnet/example/tshello/tshello.go b/tsnet/example/tshello/tshello.go index 57b8fa2a4..b5ed4c711 100644 --- a/tsnet/example/tshello/tshello.go +++ b/tsnet/example/tshello/tshello.go @@ -29,13 +29,20 @@ func main() { if err != nil { log.Fatal(err) } + defer ln.Close() + + lc, err := s.LocalClient() + if err != nil { + log.Fatal(err) + } + if *addr == ":443" { ln = tls.NewListener(ln, &tls.Config{ GetCertificate: tailscale.GetCertificate, }) } log.Fatal(http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - who, err := tailscale.WhoIs(r.Context(), r.RemoteAddr) + who, err := lc.WhoIs(r.Context(), r.RemoteAddr) if err != nil { http.Error(w, err.Error(), 500) return