// newTempFile returns a new output file in dir with the provided prefix and suffix. func newTempFile(dir, prefix, suffix string) (*os.File, error) { … } var tempFiles … var tempFilesMu … // deferDeleteTempFile marks a file to be deleted by next call to Cleanup() func deferDeleteTempFile(path string) { … } // cleanupTempFiles removes any temporary files selected for deferred cleaning. func cleanupTempFiles() error { … }