Created
January 22, 2019 23:46
-
-
Save ajbeach2/bd1506114f39cd3c965830c048727cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"os" | |
) | |
func downloadFile(filepath string, url string) (err error) { | |
// Create the file | |
out, err := os.Create(filepath) | |
if err != nil { | |
return err | |
} | |
defer out.Close() | |
// Get the data | |
resp, err := http.Get(url) | |
if err != nil { | |
return err | |
} | |
defer resp.Body.Close() | |
// Check server response | |
if resp.StatusCode != http.StatusOK { | |
return fmt.Errorf("bad status: %s", resp.Status) | |
} | |
// Writer the body to file | |
_, err = io.Copy(out, resp.Body) | |
if err != nil { | |
return err | |
} | |
return nil | |
} | |
func main(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment