Created
August 30, 2018 15:06
-
-
Save pdk/1fdb9f9158157af2fa341449a122c46b to your computer and use it in GitHub Desktop.
naive refactor of go 1 error handling
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 { | |
checkErr := func(err error) { | |
if err != nil { | |
return fmt.Errorf("copy %s %s: %v", src, dst, err) | |
} | |
} | |
r, err := os.Open(src) | |
checkErr(err) | |
defer r.Close() | |
w, err = os.Create(dst) | |
checkErr(err) | |
defer w.Close() | |
_, err = io.Copy(w, r) | |
checkErr(err) | |
err = w.Close() | |
checkErr(err) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment