-
-
Save koesie10/ba6af59e0dd8213260e5944c1464b0b1 to your computer and use it in GitHub Desktop.
This file contains 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/printer" | |
"go/token" | |
"log" | |
"os" | |
) | |
func main() { | |
src := []byte(`package main | |
import "fmt" | |
func main() { | |
fmt.Println("Hello, world!") | |
} | |
`) | |
fset := token.NewFileSet() | |
file, err := parser.ParseFile(fset, "", src, 0) | |
if err != nil { | |
log.Fatal(err) | |
} | |
ast.Inspect(file, func(n ast.Node) bool { | |
call, ok := n.(*ast.CallExpr) | |
if !ok { | |
return true | |
} | |
printer.Fprint(os.Stdout, fset, call.Fun) | |
fmt.Println() | |
return false | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment