Go http Download file

Source: Internet
Author: User
Tags sprintf


Video http download code dn.go

The overall feeling is particularly simple, the online look at the next net/http, io the use of these 2 libraries, a few minutes to write, feel that the CPP in the tool this piece of development efficiency is really poor (no wheel).

Put another go example website, https://gobyexample.com/

Package main Import ("FMT"          "io"          "net/http"          "OS"          "StrConv"      )  /*var (//url = "http://flv5.bn.netease.com/live163/store/208588/serverpush_18783_1521024752481_208588_0-1.ts"url string ="http://flv5.bn.netease.com/live163/store/208588/serverpush_18783_1521024752481_208588_0-"Url_suffix string =". Ts ")*/Func Main () {FMT. Println ("download Begin .....") URL:="http://flv5.bn.netease.com/live163/store/208588/serverpush_18783_1521024752481_208588_0-"Url_suffix:=". TS"         forI: = the; I <= the; i++{str_index:= StrConv. Itoa (i)//Convert by Itoa method//str2: = FMT. Sprintf ("%d", i)//Convert by sprintf method//FMT. Println (Str_index)//Print str1strfinal:= url+str_index+Url_suffix Res, err:=http. Get (strfinal)ifErr! =Nil {panic (err)} F, err:= OS. Create (str_index+Url_suffix)ifErr! =Nil {panic (err)} Filesize,writeerr:=io. Copy (f, Res. Body) fmt. Println (strfinal+"download Done,","file Size (byte) =", FileSize)ifWriteerr! =Nil {fmt. Println (strfinal+"Download Failed","errorinfo=", Writeerr.error ()) Panic (Err)}} FMT. Println ("download finish.")    }  

Go http Download file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.