github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/deisctl/utils/net/net.go (about) 1 // Package net contains commonly useful network functions 2 package net 3 4 import ( 5 "errors" 6 "io/ioutil" 7 "net/http" 8 ) 9 10 // Download downloads a resource from a specified 11 // source (URL) to the specified destination 12 func Download(src string, dest string) error { 13 res, err := http.Get(src) 14 if err != nil { 15 return err 16 } 17 if res.StatusCode != 200 { 18 return errors.New(res.Status) 19 } 20 defer res.Body.Close() 21 data, err := ioutil.ReadAll(res.Body) 22 if err != nil { 23 return err 24 } 25 if err = ioutil.WriteFile(dest, data, 0644); err != nil { 26 return err 27 } 28 return nil 29 }