make ls faster (#48)

This commit is contained in:
mrfly 2017-12-07 23:38:49 +08:00 committed by Jess Frazelle
parent 75dcff4501
commit 29f6d2fab9

20
main.go
View file

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"strings" "strings"
"sync"
"text/tabwriter" "text/tabwriter"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
@ -138,15 +139,20 @@ func main() {
// print header // print header
fmt.Fprintln(w, "REPO\tTAGS") fmt.Fprintln(w, "REPO\tTAGS")
var wg sync.WaitGroup
wg.Add(len(repos))
for _, repo := range repos { for _, repo := range repos {
// get the tags and print to stdout go func(repo string) {
tags, err := r.Tags(repo) // get the tags and print to stdout
if err != nil { tags, err := r.Tags(repo)
return err if err != nil {
} fmt.Printf("Get tags of [%s] error: %s", repo, err)
}
fmt.Fprintf(w, "%s\t%s\n", repo, strings.Join(tags, ", ")) fmt.Fprintf(w, "%s\t%s\n", repo, strings.Join(tags, ", "))
wg.Done()
}(repo)
} }
wg.Wait()
w.Flush() w.Flush()
return nil return nil