1
0
mirror of https://github.com/beego/bee.git synced 2024-06-10 03:33:33 +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

26
util.go
View File

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