I have 2 different packages(pkg1, pkg2), in first i have code that calls function from another package
file#1
package pkg1
import "pkg2"
import "reflect"
type User struct {
name string
...
}
func main() {
fmt.Println(reflect.TypeOf((*User)(nil)) //=> *User
pkg2.RegisterStruct(reflect.TypeOf((*User)(nil))
//pkg2.RegisterStruct(reflect.TypeOf(&User{}) // also tried this way
}
file#2
package pkg2
import "reflect"
func RegisterStruct(u interface{}) { // also tried to have argument type as reflect.Type
fmt.Println(u) //=> *reflect.rtype
}
Why type was reflect.rtype
instead of *User
?
And how do i correctly pass type to another pkg?