package mc import ( "fmt" "io" "io/ioutil" "net/http" "os" ) func httpReq(url string) []byte { resp, err := http.Get(url) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } return body } func downloadFile(filepath string, url string) error { // Get the data resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() // Create the file out, err := os.Create(filepath) if err != nil { return err } defer out.Close() // Write the body to file _, err = io.Copy(out, resp.Body) return err } //https://opensource.com/article/18/6/copying-files-go func copy(src, dst string) (int64, error) { sourceFileStat, err := os.Stat(src) if err != nil { return 0, err } if !sourceFileStat.Mode().IsRegular() { return 0, fmt.Errorf("%s is not a regular file", src) } source, err := os.Open(src) if err != nil { return 0, err } defer source.Close() destination, err := os.Create(dst) if err != nil { return 0, err } defer destination.Close() nBytes, err := io.Copy(destination, source) return nBytes, err }