Last active
August 30, 2018 16:55
-
-
Save pdk/b31627c5c5d93747c5698f7f6be858cc to your computer and use it in GitHub Desktop.
checkErr consumer
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
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