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:
committed by
Brad Fitzpatrick
parent
8cfbaa717d
commit
2a64c03c95
@@ -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
|
||||
})
|
||||
|
||||
@@ -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)}),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user