Skip to content

Instantly share code, notes, and snippets.

@pdk
Last active August 30, 2018 16:55
Show Gist options
  • Save pdk/b31627c5c5d93747c5698f7f6be858cc to your computer and use it in GitHub Desktop.
Save pdk/b31627c5c5d93747c5698f7f6be858cc to your computer and use it in GitHub Desktop.
checkErr consumer
func CopyFile(src, dst string) error {
makro checkErr(..., err error) ... {
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
}
}
r := checkErr(os.Open(src))
defer r.Close()
w := checkErr(os.Create(dst))
defer w.Close()
checkErr(io.Copy(w, r))
checkErr(w.Close())
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment