Skip to content

Instantly share code, notes, and snippets.

@erukiti
Created Dec 10, 2014
Embed
What would you like to do?
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
)
func downloader(url string) {
tmp := strings.Split(url, "/")
fileName := tmp[len(tmp)-1]
resp, err := http.Get(url)
if err != nil {
fmt.Println(err)
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
ioutil.WriteFile(fileName, body, 0644)
}
func main() {
// url := "http://yukkurisinai.net/gopher.png"
for _, url := range os.Args[1:] {
downloader(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment