github.com/kcmerrill/common.go@v0.0.0-20180608223308-4114128a6803/file/get.go (about) 1 package file 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 ) 8 9 // Get will return a url in []bytes 10 func Get(url string) ([]byte, error) { 11 resp, err := http.Get(url) 12 13 if err != nil || resp.StatusCode != 200 { 14 return nil, fmt.Errorf("Unable to find file: " + url) 15 } 16 17 defer resp.Body.Close() 18 body, readErr := ioutil.ReadAll(resp.Body) 19 if readErr != nil { 20 return nil, fmt.Errorf("Unable to read the body of the file: " + url) 21 } 22 return body, nil 23 }