code: func createFile(path string, write func(*os.File) error) (err error) {
  	file, err := os.Create(path)
  	if err != nil {
  		return err
  	}
  	defer func() {
  		closeErr := file.Close()
  		if err == nil {
  			err = closeErr
  		}
  	}()
  	return write(file)
  }
docs: // createFile creates a file and calls the function to write file content.
  //
  // Does NOT cleanup the file if something fails midway.