func CopyFile(src, dst string) error { r, err := os.Open(src) if err != nil { return err } defer r.Close() w, err := os.Create(dst) if err != nil { return err } defer w.Close() if _, err := io.Copy(w, r); err != nil { return err } if err := w.Close(); err != nil { return err } }
if r, err := os.Open(src); err != nil { return err } defer r.Close()
You could have smaller discrete functions that abstract the handling of each action a little bit and be more reusable, or is that not possible in Go
These shorter functions need to signal their failure somehow, so calling them looks exactly like the example.