From 35384b463e3bf63030a4fe54bbe1abccfd9c4fbd Mon Sep 17 00:00:00 2001 From: Faissal Elamraoui Date: Sun, 20 Nov 2016 11:55:44 +0100 Subject: [PATCH] This allows the isBeegoProject() function to do the walking inside a Goroutine --- util.go | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/util.go b/util.go index c3cc754..ef28fb2 100644 --- a/util.go +++ b/util.go @@ -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 {