csvtools Provide tools to work with csv files.
- Flattener: Flat your structs to csv files and merge them after unmarshal.
Marshal
- Each struct that contains arrays must implement the
Recordinterface. - For each array field in your struct add another field with type of your array field's type and also set tag of that array field to dash(
-) to ignore for csv. e.g.,
struct Book{
Authors `csv:"-"` // please note csv tag value is dash.
Author `csv:"author_,inline"`
}-
For each Array field in your struct create a new instance of
Groupand return created groups in the struct as return param ofCSVGroups()method. -
call to
DecomposeRecordsdo decompose your records. -
Simply call to the
csvutil.Marshalmethod to marshal your list.
Unmarshal
-
Simply use
csvutil.Unmarshalto unmarshal your csv records to your struct list. -
Call to the
ComposeRecordsto group records and then merge them. it will return array of merged records.