Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapReader ¶
MapReader contains all our necessary data for the various methods to function
func NewReader ¶
NewReader returns a new MapReader struct. It can be created the same way a regular CSV file is created, by providing it with a reference to a file reader, ideally one that points to a CSV file. I'm using an interface here so that, should the need arise, you can provide your CSV to the package in a variety of non-file based ways. Note that here we read the first row of the file without setting any non-standard values for the CSV package's Reader struct. If it becomes apparent that the ability to change these parameters is vital, then I'm more than happy to figure out an idiomatic way to accomplish that task.
func (*MapReader) CreateHeaderIndexMap ¶
func (m *MapReader) CreateHeaderIndexMap()
CreateHeaderIndexMap creates a map of header strings to their indices in the array generated by encoding/csv's reader. For instance, if your CSV file looks something like this:
--------------------- | one | two | three | --------------------- | A | B | C | ---------------------
Go's generated array for the header row will be [ "one", "two", "three" ]. Cartogopher's generated map for the header row will be { "one": 1, "two": 2, "three": 3 }
func (MapReader) CreateRowMap ¶
CreateRowMap takes a given CSV array and returns a map of column names to the values contained therein. For instance, if your CSV file looks something like this:
--------------------- | one | two | three | --------------------- | A | B | C | ---------------------
The return result will be:
{ "one": "A", "two": "B", "three": "C", }
Note that this requires the HeaderIndexMap to be created and not a null value.