This is a created article in which the information may have evolved or changed.
Package Mainimport ("FMT" "io" "net/http" "OS" "Strings" "Sync") var go_lock sync. Waitgroupfunc Main () {if Len (OS. Args) < 2 {fmt. Println ("Param error!") Return}for _, V: = Range os. Args[1:] {go_lock. ADD (1) fmt. Printf ("Get%s\n", v) Go Client (v)}go_lock. Wait ()}func client (URL string) {resp, err: = http. Get (URL) if err! = Nil {fmt. PRINTLN (Err) return}fmt. Printf ("Host%s \nrequest Status:%d\nfilelength:%d bytes\n", resp. Request.URL.Host, resp. Statuscode,resp. ContentLength) defer func () {resp. Body.close () Go_lock. Done ()} () Path: = resp. Request.URL.Pathif!strings. Hassuffix (Path, "/") {Path = path + "/"}list: = Strings. Split (Path, "/") FileName: = List[len (list) -2]file, err: = OS. Create (filename) if err! = Nil {fmt. PRINTLN (Err) Return}io. Copy (File, resp. Body) File.close ()}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.