Skip to content

Instantly share code, notes, and snippets.

@sitetester
Last active September 7, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sitetester/b7184388f5ea5454197958e0c497f462 to your computer and use it in GitHub Desktop.
Save sitetester/b7184388f5ea5454197958e0c497f462 to your computer and use it in GitHub Desktop.
This will create directory (if not exists) and will write a new file to it
resp, _ := http.Get(GoogleUrl)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
dir := "resources"
if _, err := os.Stat(dir); os.IsNotExist(err) {
os.Mkdir("."+string(filepath.Separator)+dir, 0777)
}
newPath := filepath.Join(dir, "google.html")
fmt.Println(newPath)
ioutil.WriteFile(newPath, body, 0644)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment