import (
"go/parser"
"go/token"
"go/ast"
)
func HasMain(file string) (bool, error) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, file, nil, 0)
if err != nil {
return false, err
}
for _, dec := range f.Decls {
fd, ok := dec.(*ast.FuncDecl)
if ok && fd.Name.Name == "main" {
return true, nil
}
}
return false, nil
}