Try to extract functions code from .go files and run some promt on it (like comment this function)
Example:
package main
import (
"go/ast"
"go/parser"
"go/token"
"log"
"os"
)
func main() {
fset := token.NewFileSet()
// Parse the .go file
f, err := parser.ParseFile(fset, "yourfile.go", nil, 0)
if err != nil {
log.Fatal(err)
}
// Inspect the AST and print function declarations
ast.Inspect(f, func(n ast.Node) bool {
switch x := n.(type) {
case *ast.FuncDecl:
// This is a function declaration
// Print the function name and its body
start := fset.Position(x.Body.Lbrace)
end := fset.Position(x.Body.Rbrace)
log.Printf("Function: %s, Start: %s, End: %s\n", x.Name.Name, start, end)
}
return true
})
}
Try to extract functions code from .go files and run some promt on it (like comment this function)
Example: