From 88d803f723fc6fafa9e36a57a087aebaa216db17 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Wed, 24 Dec 2025 14:02:22 -0800 Subject: [PATCH] all: cleanup minor linting issues and license language - change "AUTHORS" to "contributors" in copyright line, since we don't maintain an AUTHORS file in this repo. - fix use of deprecated tailscale.LocalClient - remove embedded fields in selector when not needed - add some missing error checks Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris --- app.go | 2 +- app_test.go | 2 +- auth.go | 12 ++++++------ cmd/caddy/main.go | 2 +- command.go | 7 ++++--- module.go | 26 +++++++++++++------------- module_test.go | 4 ++-- transport.go | 2 +- 8 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app.go b/app.go index 9f8ec4b..2bac087 100644 --- a/app.go +++ b/app.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package tscaddy diff --git a/app_test.go b/app_test.go index 655d0f5..7b9c265 100644 --- a/app_test.go +++ b/app_test.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package tscaddy diff --git a/auth.go b/auth.go index 8309707..c84ac09 100644 --- a/auth.go +++ b/auth.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package tscaddy @@ -17,7 +17,7 @@ import ( "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile" "github.com/caddyserver/caddy/v2/modules/caddyhttp" "github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth" - "tailscale.com/client/tailscale" + "tailscale.com/client/local" "tailscale.com/tsnet" ) @@ -32,7 +32,7 @@ func init() { // that node will be used to identify the user information for inbound requests. // Otherwise, it will attempt to find and use the local tailscaled daemon running on the system. type Auth struct { - localclient *tailscale.LocalClient + localclient *local.Client } func (Auth) CaddyModule() caddy.ModuleInfo { @@ -65,7 +65,7 @@ func findTsnetListener(ln net.Listener) (_ tsnetListener, ok bool) { // if ln has an embedded net.Listener field, unwrap it. s := reflect.ValueOf(ln) - if s.Kind() == reflect.Ptr { + if s.Kind() == reflect.Pointer { s = s.Elem() } if s.Kind() != reflect.Struct { @@ -93,7 +93,7 @@ type wrappedListener interface { // client returns the tailscale LocalClient for the TailscaleAuth module. // If the LocalClient has not already been configured, the provided request will be used to // lookup the tailscale node that serviced the request, and get the associated LocalClient. -func (ta *Auth) client(r *http.Request) (*tailscale.LocalClient, error) { +func (ta *Auth) client(r *http.Request) (*local.Client, error) { if ta.localclient != nil { return ta.localclient, nil } @@ -113,7 +113,7 @@ func (ta *Auth) client(r *http.Request) (*tailscale.LocalClient, error) { if ta.localclient == nil { // default to empty client that will talk to local tailscaled - ta.localclient = new(tailscale.LocalClient) + ta.localclient = new(local.Client) } return ta.localclient, nil diff --git a/cmd/caddy/main.go b/cmd/caddy/main.go index 2677cb0..df0b671 100644 --- a/cmd/caddy/main.go +++ b/cmd/caddy/main.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package main diff --git a/command.go b/command.go index 506845d..c9cb71a 100644 --- a/command.go +++ b/command.go @@ -1,5 +1,5 @@ // Copyright 2015 Matthew Holt and The Caddy Authors -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package tscaddy @@ -109,9 +109,10 @@ func cmdTailscaleProxy(fs caddycmd.Flags) (int, error) { } } if fromAddr.Port == "" { - if fromAddr.Scheme == "http" { + switch fromAddr.Scheme { + case "http": fromAddr.Port = httpPort - } else if fromAddr.Scheme == "https" { + case "https": fromAddr.Port = httpsPort } } diff --git a/module.go b/module.go index a9b42d0..586c30c 100644 --- a/module.go +++ b/module.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 // Package tscaddy provides a set of Caddy modules to integrate Tailscale into Caddy. @@ -26,7 +26,7 @@ import ( "github.com/caddyserver/certmagic" "github.com/tailscale/tscert" "go.uber.org/zap" - "tailscale.com/client/tailscale" + "tailscale.com/client/local" "tailscale.com/hostinfo" "tailscale.com/tsnet" ) @@ -76,7 +76,7 @@ func getTCPListener(c context.Context, network string, host string, portRange st lnKey := fmt.Sprintf("tailscale/%s:%s:%s", host, network, port) sharedLn, _, err := tailscaleListeners.LoadOrNew(lnKey, func() (caddy.Destructor, error) { - ln, err := node.Server.Listen(network, ":"+port) + ln, err := node.Listen(network, ":"+port) if err != nil { return nil, err } @@ -127,7 +127,7 @@ func getTLSListener(c context.Context, network string, host string, portRange st lnKey := fmt.Sprintf("tailscale+tls/%s:%s:%s", host, network, port) sharedLn, _, err := tailscaleListeners.LoadOrNew(lnKey, func() (caddy.Destructor, error) { - ln, err := node.Server.Listen(network, ":"+port) + ln, err := node.Listen(network, ":"+port) if err != nil { return nil, err } @@ -221,7 +221,7 @@ func getUDPListener(c context.Context, network string, host string, portRange st return nil, fmt.Errorf("no suitable Tailscale IP address found for UDP listener") } - pc, err := node.Server.ListenPacket(network, ap.String()) + pc, err := node.ListenPacket(network, ap.String()) if err != nil { return nil, err } @@ -441,7 +441,7 @@ type tailscaleSharedListener struct { } func (tsl *tailscaleSharedListener) Destruct() error { - return tsl.Listener.Close() + return tsl.Close() } // tailscaleFakeCloseListener is similar to Caddy's fakeCloseListener @@ -468,13 +468,13 @@ func (tfcl *tailscaleFakeCloseListener) Accept() (net.Conn, error) { func (tfcl *tailscaleFakeCloseListener) Close() error { if tfcl.closed.CompareAndSwap(false, true) { _, _ = tailscaleListeners.Delete(tfcl.key) - tfcl.node.Close() + return tfcl.node.Close() } return nil } func (tfcl *tailscaleFakeCloseListener) Unwrap() net.Listener { - return tfcl.tailscaleSharedListener.Listener + return tfcl.Listener } // tailscaleSharedPacketConn is similar to tailscaleSharedListener but for packet connections @@ -484,7 +484,7 @@ type tailscaleSharedPacketConn struct { } func (tspc *tailscaleSharedPacketConn) Destruct() error { - return tspc.PacketConn.Close() + return tspc.Close() } // tailscaleFakeClosePacketConn is similar to tailscaleFakeCloseListener but for packet connections @@ -511,13 +511,13 @@ func (tfcpc *tailscaleFakeClosePacketConn) ReadFrom(p []byte) (n int, addr net.A func (tfcpc *tailscaleFakeClosePacketConn) Close() error { if tfcpc.closed.CompareAndSwap(false, true) { _, _ = tailscaleListeners.Delete(tfcpc.key) - tfcpc.node.Close() + return tfcpc.node.Close() } return nil } func (tfcpc *tailscaleFakeClosePacketConn) Unwrap() net.PacketConn { - return tfcpc.tailscaleSharedPacketConn.PacketConn + return tfcpc.PacketConn } // tsnetMuxTransport is an [http.RoundTripper] that sends requests to the LocalAPI @@ -562,9 +562,9 @@ func (t *tsnetMuxTransport) RoundTrip(req *http.Request) (*http.Response, error) return rt.RoundTrip(req) } -// localAPITransport is an [http.RoundTripper] that sends requests to a [tailscale.LocalClient]'s LocalAPI. +// localAPITransport is an [http.RoundTripper] that sends requests to a [local.Client]'s LocalAPI. type localAPITransport struct { - *tailscale.LocalClient + *local.Client } func (t *localAPITransport) RoundTrip(req *http.Request) (*http.Response, error) { diff --git a/module_test.go b/module_test.go index 6645567..2d11124 100644 --- a/module_test.go +++ b/module_test.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package tscaddy @@ -449,7 +449,7 @@ func Test_Listen(t *testing.T) { } // Close the listener - ln.(io.Closer).Close() + must.Do(ln.(io.Closer).Close()) // Check that listener reference is gone lcount, lexists = tailscaleListeners.References(listenerKey) diff --git a/transport.go b/transport.go index d7e10be..1abe330 100644 --- a/transport.go +++ b/transport.go @@ -1,4 +1,4 @@ -// Copyright (c) Tailscale Inc & AUTHORS +// Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: Apache-2.0 package tscaddy