Created
January 18, 2016 09:28
-
-
Save kaneshin/06239905614582a6a50b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os/exec" | |
"sync" | |
) | |
var ( | |
parallel = flag.Bool("parallel", true, "") | |
) | |
func download(url string) error { | |
fmt.Printf("Start to download: %s\n", url) | |
cmd := exec.Command("wget", url) | |
return cmd.Run() | |
} | |
func main() { | |
flag.Parse() | |
args := flag.Args() | |
if *parallel { | |
wg := new(sync.WaitGroup) | |
for _, v := range args { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
download(v) | |
}() | |
} | |
wg.Wait() | |
} else { | |
for _, v := range args { | |
download(v) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment