Skip to content

Instantly share code, notes, and snippets.

@pdk
Last active August 30, 2018 16:02
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 pdk/dd9784b713cbd59a7adda379cd5ce6b2 to your computer and use it in GitHub Desktop.
Save pdk/dd9784b713cbd59a7adda379cd5ce6b2 to your computer and use it in GitHub Desktop.
example of new makro keyword
func CopyFile(src, dst string) error {
makro checkErr() {
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
}
}
r, err := os.Open(src)
checkErr()
defer r.Close()
w, err = os.Create(dst)
checkErr()
defer w.Close()
_, err = io.Copy(w, r)
checkErr()
err = w.Close()
checkErr()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment