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

93 Views Asked by At

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?

Edit 1: the problem I'm trying to solve is to write a code generator that would create a code doing something with the functions that I'm passing to that code generator. Code generator is a library that gets called in my utility's main function that should somehow take functions that I define in some packages and create code that somehow uses those functions.

0

There are 0 best solutions below