效果
代码
package main import ( "fmt" "io" "net/http" "os" ) var url, path string func main() { if len(os.Args) != 3 { fmt.Println("usage:wget.exe http://Y4er.com/cmd.exe cmd.exe") os.Exit(0) } url, path = os.Args[1], os.Args[2] fmt.Println("你要下载的文件是:" + url) fmt.Println("将要保存到:" + path) Download(url, path) } func Download(url string, path string) { out, err := os.Create(path) check(err) defer out.Close() res, err := http.Get(url) check(err) defer res.Body.Close() _, err = io.Copy(out, res.Body) check(err) fmt.Println("保存成功,自行检查" + path) } func check(err error) { if err != nil { panic(err) } }
编译好的win64位下载链接:http://Y4er.com/file/go-wget.exe
原创文章,作者:Y4er,未经授权禁止转载!如若转载,请联系作者:Y4er