Created
September 11, 2020 23:01
-
-
Save csthompson/d4b44c91c8d1894733ecad1f1bfcdc01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"go/ast" | |
"go/parser" | |
"go/token" | |
) | |
func main() { | |
//Create a new token set for the file | |
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 Return Statements | |
funcCall, ok := n.(*ast.CallExpr) | |
if ok { | |
mthd, ok := funcCall.Fun.(*ast.SelectorExpr) | |
if ok { | |
_, ok = mthd.X.(*ast.Ident) | |
if ok { | |
if mthd.Sel.Name == "Publish" && mthd.X.(*ast.Ident).Name == "ec" { | |
fmt.Printf("Topic: %s \n", funcCall.Args[0].(*ast.BasicLit).Value) | |
} | |
} | |
} | |
} | |
return true | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment