How to make call graph when my functions are referenced from other golang project (package)

func main() { mainutils.Run(run) }

func run(ctx context.Context) error {
flg, err := getFlags()
if err != nil {
return errors.Wrap(err, “get flags”)
}
cl, err := mainutils.Init(mainutils.Config{
})
if err != nil {
return errors.Wrap(err, “init”)
}
defer cl()
return ctxutils.RunFuncs(ctx, ctxutils.Funcs{
“AMQP”: func(ctx context.Context) error {
return runAMQP(ctx, flg)
},
“debug”: func(ctx context.Context) error {
return debugutils.RunHTTPServer(ctx, flg.debug)
},
})
}

/main.go:22:14: undeclared name: getFlags
/main.go:38:11: undeclared name: runAMQP
The command callgraph main.go returns these errors?

You need package names in front of imported variables or functions.

As they are starting with lowercase letters they can’t be imported, as nothing exports them…

I do not know callgraph, but does go build work? If not fix that first to make sure you have a valid program.

True :smile: I just saw flag line at the beginning.

Yes go build works fine the binaries are generated fine. The problem is this the run function is passed as an argument to some other library and then there context is being set and runAMQP and other functions are being called. It is in some other project.
You see mainutils.Run(run)?

Yeah, I see it, but I do not know anything aput that package. Also I have never seen anything in go that makes identifiers apear out of thin air…

So perhaps you have some other files in the same folder that also belong to package main and define those functions, which go build uses correctly but callgraph does not?

But without seeing the complete context of your project (or at least a minified version which shows the same behaviour) its hard to tell.

I am sorry but passing the whole path of the project generates the callgraph. I was only doing callgraph main.go. However, you have to pass whole project path.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.