mardi 5 novembre 2019

Is there a way to extract package path from reflect.Func? [duplicate]

This question already has an answer here:

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