Working with two different CSV file formats
In this section we are going to implement a separate command-line utility that works with two different CSV formats. The reason we are doing this is that there are times when you will need your utilities to be able to work with multiple data formats.
Remember that the records of each CSV format are stored using their own Go structure under a different variable name. As a result, we need to implement sort.Interface
for both CSV formats and therefore for both slice variables.
The two supported formats are the following:
- Format 1: name, surname, telephone number, time of last access
- Format 2: name, surname, area code, telephone number, time of last access
As the two CSV formats that are going to be used have a different number of fields, the utility determines the format that is being used by the number of fields found in the first record that was read and acts accordingly. After that, the data will be sorted...