types/ptr: deprecate ptr.To, use Go 1.26 new

Updates #18682

Change-Id: I62f6aa0de2a15ef8c1435032c6aa74a181c25f8f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2026-03-05 22:48:46 +00:00
committed by Brad Fitzpatrick
parent 8cfbaa717d
commit 2a64c03c95
96 changed files with 429 additions and 532 deletions
+4 -5
View File
@@ -12,7 +12,6 @@ import (
"time"
"tailscale.com/tailcfg"
"tailscale.com/types/ptr"
)
// NodeMutation is the common interface for types that describe
@@ -55,7 +54,7 @@ type NodeMutationOnline struct {
}
func (m NodeMutationOnline) Apply(n *tailcfg.Node) {
n.Online = ptr.To(m.Online)
n.Online = new(m.Online)
}
// NodeMutationLastSeen is a NodeMutation that says a node's LastSeen
@@ -66,14 +65,14 @@ type NodeMutationLastSeen struct {
}
func (m NodeMutationLastSeen) Apply(n *tailcfg.Node) {
n.LastSeen = ptr.To(m.LastSeen)
n.LastSeen = new(m.LastSeen)
}
var peerChangeFields = sync.OnceValue(func() []reflect.StructField {
var fields []reflect.StructField
rt := reflect.TypeFor[tailcfg.PeerChange]()
for i := range rt.NumField() {
fields = append(fields, rt.Field(i))
for field := range rt.Fields() {
fields = append(fields, field)
}
return fields
})
+3 -4
View File
@@ -14,7 +14,6 @@ import (
"tailscale.com/tailcfg"
"tailscale.com/types/logger"
"tailscale.com/types/opt"
"tailscale.com/types/ptr"
)
// tests mapResponseContainsNonPatchFields
@@ -117,7 +116,7 @@ func TestMutationsFromMapResponse(t *testing.T) {
name: "patch-online",
mr: fromChanges(&tailcfg.PeerChange{
NodeID: 1,
Online: ptr.To(true),
Online: new(true),
}),
want: muts(NodeMutationOnline{1, true}),
},
@@ -125,7 +124,7 @@ func TestMutationsFromMapResponse(t *testing.T) {
name: "patch-online-false",
mr: fromChanges(&tailcfg.PeerChange{
NodeID: 1,
Online: ptr.To(false),
Online: new(false),
}),
want: muts(NodeMutationOnline{1, false}),
},
@@ -133,7 +132,7 @@ func TestMutationsFromMapResponse(t *testing.T) {
name: "patch-lastseen",
mr: fromChanges(&tailcfg.PeerChange{
NodeID: 1,
LastSeen: ptr.To(time.Unix(12345, 0)),
LastSeen: new(time.Unix(12345, 0)),
}),
want: muts(NodeMutationLastSeen{1, time.Unix(12345, 0)}),
},