From 29f6d2fab954e89caaa86d1d914b2c5ed6654974 Mon Sep 17 00:00:00 2001 From: mrfly Date: Thu, 7 Dec 2017 23:38:49 +0800 Subject: [PATCH] make ls faster (#48) --- main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 16ce95cb..7df71101 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "strings" + "sync" "text/tabwriter" "github.com/Sirupsen/logrus" @@ -138,15 +139,20 @@ func main() { // print header fmt.Fprintln(w, "REPO\tTAGS") + var wg sync.WaitGroup + wg.Add(len(repos)) for _, repo := range repos { - // get the tags and print to stdout - tags, err := r.Tags(repo) - if err != nil { - return err - } - - fmt.Fprintf(w, "%s\t%s\n", repo, strings.Join(tags, ", ")) + go func(repo string) { + // get the tags and print to stdout + tags, err := r.Tags(repo) + if err != nil { + fmt.Printf("Get tags of [%s] error: %s", repo, err) + } + fmt.Fprintf(w, "%s\t%s\n", repo, strings.Join(tags, ", ")) + wg.Done() + }(repo) } + wg.Wait() w.Flush() return nil