How can I create a map from all of the functions found in another file in Go? It's pretty easy to get the names of them using the following code, but I haven't found a way to get the actual functions, or for the desired code to work.
fileSet := token.NewFileSet()
ast, err := parser.ParseFile(fileSet, "funcFile.go", nil, 0)
if err != nil {
panic(err)
}
for key := range ast.Scope.Objects {
fmt.Println(key) //
}
Desired result:
funcFile.go
imports ...
func returnTrue () bool {return true}
mapFile.go
func CreateFuncMap () {
fns := make(map[string]func(bars []Types.MarketData) bool)
otherFuncs := getFuncsFromFile("funcFile.go")
for _, fn := range otherFuncs {
fns[fn.Name] = fn
}
}