This question already has an answer here:
- How to get path of imported package 1 answer
When reflect.TypeOf
is used on functions, resultant object has empty PkgPath()
. Full example showing this is as follows:
// file 1, package foo:
func New() *Foo {
return nil
}
// file 2, package main, main func:
typ := reflect.TypeOf(foo.New)
fmt.Printf("typ.PkgPath() is '%s'\n", typ.PkgPath())
Do I understand right that there is no need to get pkg path from functions and there is no way to learn it given reflect.Type alone for funcs? If not - is there still a way to extract it somehow?
Aucun commentaire:
Enregistrer un commentaire