@@ -50,28 +50,44 @@ func doCheck(pkgs []goutil.Package) int {
5050 needUpdatePkgs := []goutil.Package {}
5151
5252 print .Info ("check binary under $GOPATH/bin or $GOBIN" )
53- for i , v := range pkgs {
54- if v .ModulePath == "" {
55- print .Err (fmt .Errorf (countFmt + " check failure: %s" ,
56- i + 1 , len (pkgs ), v .Name ))
57- result = 1
58- continue
53+ ch := make (chan updateResult )
54+ checker := func (p goutil.Package , result chan updateResult ) {
55+ var err error
56+ if p .ModulePath == "" {
57+ err = fmt .Errorf (" %s is not installed by 'go install' (or permission incorrect)" , p .Name )
58+ } else {
59+ var latestVer string
60+ latestVer , err = goutil .GetLatestVer (p .ModulePath )
61+ if err != nil {
62+ err = fmt .Errorf (" %s %w" , p .Name , err )
63+ }
64+ p .Version .Latest = latestVer
65+ if ! goutil .IsAlreadyUpToDate (* p .Version ) {
66+ needUpdatePkgs = append (needUpdatePkgs , p )
67+ }
5968 }
6069
61- latestVer , err := goutil .GetLatestVer (v .ModulePath )
62- if err != nil {
63- print .Err (fmt .Errorf (countFmt + " check failure: %w" ,
64- i + 1 , len (pkgs ), err ))
65- result = 1
66- continue
70+ r := updateResult {
71+ pkg : p ,
72+ err : err ,
6773 }
68- v .Version .Latest = latestVer
74+ result <- r
75+ }
6976
70- print .Info (fmt .Sprintf (countFmt + " check success: %s (%s)" ,
71- i + 1 , len (pkgs ), v .ModulePath , v .VersionCheckResultStr ()))
77+ // check all package
78+ for _ , v := range pkgs {
79+ go checker (v , ch )
80+ }
7281
73- if ! goutil .IsAlreadyUpToDate (* v .Version ) {
74- needUpdatePkgs = append (needUpdatePkgs , v )
82+ // print result
83+ for i := 0 ; i < len (pkgs ); i ++ {
84+ v := <- ch
85+ if v .err == nil {
86+ print .Info (fmt .Sprintf (countFmt + " %s (%s)" ,
87+ i + 1 , len (pkgs ), v .pkg .ModulePath , v .pkg .VersionCheckResultStr ()))
88+ } else {
89+ result = 1
90+ print .Err (fmt .Errorf (countFmt + "%s" , i + 1 , len (pkgs ), v .err .Error ()))
7591 }
7692 }
7793
0 commit comments