all: use reflect.TypeFor now available in Go 1.22 (#11078)

Updates #cleanup

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
Joe Tsai
2024-02-08 17:34:22 -08:00
committed by GitHub
parent efddad7d7d
commit 94a4f701c2
18 changed files with 31 additions and 38 deletions

View File

@@ -72,7 +72,7 @@ func (m NodeMutationLastSeen) Apply(n *tailcfg.Node) {
var peerChangeFields = sync.OnceValue(func() []reflect.StructField {
var fields []reflect.StructField
rt := reflect.TypeOf((*tailcfg.PeerChange)(nil)).Elem()
rt := reflect.TypeFor[tailcfg.PeerChange]()
for i := 0; i < rt.NumField(); i++ {
fields = append(fields, rt.Field(i))
}

View File

@@ -27,7 +27,7 @@ func TestMapResponseContainsNonPatchFields(t *testing.T) {
case reflect.Bool:
return reflect.ValueOf(true)
case reflect.String:
if reflect.TypeOf(opt.Bool("")) == t {
if reflect.TypeFor[opt.Bool]() == t {
return reflect.ValueOf("true").Convert(t)
}
return reflect.ValueOf("foo").Convert(t)
@@ -43,7 +43,7 @@ func TestMapResponseContainsNonPatchFields(t *testing.T) {
panic(fmt.Sprintf("unhandled %v", t))
}
rt := reflect.TypeOf(tailcfg.MapResponse{})
rt := reflect.TypeFor[tailcfg.MapResponse]()
for i := 0; i < rt.NumField(); i++ {
f := rt.Field(i)