1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 15:10:54 +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 { 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
} }
if len(hasBeegoRegex.Find(data)) > 0 { // Skip sub-directories
mainFiles = append(mainFiles, fpath) if !f.IsDir() {
} var data []byte
} data, err = ioutil.ReadFile(fpath)
return nil if err != nil {
}) c <- err
return nil
}
if err != nil { if len(hasBeegoRegex.Find(data)) > 0 {
log.Fatalf("Unable to walk '%s' tree: %v", thePath, err) mainFiles = append(mainFiles, fpath)
return false }
}
return nil
})
close(c)
}()
if err := <-c; err != nil {
logger.Fatalf("Unable to walk '%s' tree: %s", thePath, err)
} }
if len(mainFiles) > 0 { if len(mainFiles) > 0 {