Skip to content

Instantly share code, notes, and snippets.

@csthompson
Last active September 11, 2020 04:40
Show Gist options
  • Save csthompson/eae418eb29c573220b45fd00eeb9a934 to your computer and use it in GitHub Desktop.
Save csthompson/eae418eb29c573220b45fd00eeb9a934 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
func main() {
//Create a FileSet to work with
fset := token.NewFileSet()
//Parse the file and create an AST
file, err := parser.ParseFile(fset, "../nats_publisher/main.go", nil, parser.ParseComments)
if err != nil {
panic(err)
}
ast.Inspect(file, func(n ast.Node) bool {
// Find Function Call Statements
funcCall, ok := n.(*ast.CallExpr)
if ok {
fmt.Println(funcCall.Fun)
}
return true
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment