...

/

Cleaning Up Temporary Files

Cleaning Up Temporary Files

Learn how to clean up the temporary files from the Markdown preview tool.

Overview

Currently, our program doesn’t clean up the temporary files because the method we used to create them doesn’t automatically clean them up. As we can see, running the tool multiple times creates different files:

This is expected as the program can’t know how and when the files will be used. It’s our responsibility to delete the temporary files to keep the system clean.

In our program, we can use the function os.Remove() to delete the files when they’re no longer needed. In general, we defer the call to this function using the defer statement to ensure the file is deleted when the current ...