Loading and saving data on disk

Do you remember the keyValue.go application from Chapter 4, The Uses of Composite Types? Well, it was far from perfect, so in this section you will learn how to save the data of a key-value store on disk and how to load it back into memory when you next start your application.

We are going to create two new functions, one named save() for saving data to disk and another named load() for retrieving the data from disk. Thus, we will only present the code differences between keyValue.go and kvSaveLoad.go using the diff(1) UNIX command-line utility.

The diff(1) UNIX command-line utility can be very convenient when you want to spot the differences between two text files. You can learn more about it by executing ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.