I'm trying to check the type of a struct in Go. This was the best way I could come up with. Is there a better way to do it, preferably without initializing a struct?
package main
import (
"fmt"
"reflect"
)
type Test struct{
foo int
}
func main() {
t := Test{5}
fmt.Println(reflect.TypeOf(t) == reflect.TypeOf(Test{}))
}
Aucun commentaire:
Enregistrer un commentaire