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