1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 20:20:49 +00:00

This allows the isBeegoProject() function to do the walking inside a Goroutine

This commit is contained in:
Faissal Elamraoui 2016-11-20 11:55:44 +01:00
parent 7fcbba0f53
commit 35384b463e

38
util.go
View File

@ -70,24 +70,34 @@ func GetGOPATHs() []string {
func isBeegoProject(thePath string) bool {
mainFiles := []string{}
hasBeegoRegex := regexp.MustCompile(`(?s)package main.*?import.*?\(.*?github.com/astaxie/beego".*?\).*func main()`)
c := make(chan error)
// Walk the application path tree to look for main files.
// Main files must satisfy the 'hasBeegoRegex' regular expression.
err := filepath.Walk(thePath, func(fpath string, f os.FileInfo, err error) error {
if !f.IsDir() { // Skip sub-directories
data, _err := ioutil.ReadFile(fpath)
if _err != nil {
return _err
go func() {
filepath.Walk(thePath, func(fpath string, f os.FileInfo, err error) error {
if err != nil {
return nil
}
if len(hasBeegoRegex.Find(data)) > 0 {
mainFiles = append(mainFiles, fpath)
}
}
return nil
})
// Skip sub-directories
if !f.IsDir() {
var data []byte
data, err = ioutil.ReadFile(fpath)
if err != nil {
c <- err
return nil
}
if err != nil {
log.Fatalf("Unable to walk '%s' tree: %v", thePath, err)
return false
if len(hasBeegoRegex.Find(data)) > 0 {
mainFiles = append(mainFiles, fpath)
}
}
return nil
})
close(c)
}()
if err := <-c; err != nil {
logger.Fatalf("Unable to walk '%s' tree: %s", thePath, err)
}
if len(mainFiles) > 0 {