Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AllRowsCsvRecordPredicate = func(r CsvRecord) bool { return true }
AllRowsCsvRecordPredicate is an always true condition. All rows will be processed
var RowsWithoutIDsCsvRecordPredicate = func(r CsvRecord) bool {
return r.ID == ""
}
RowsWithoutIDsCsvRecordPredicate filters rows with IDs. Only rows without IDs will be processed
var TodaysRowsCsvRecordPredicate = func(r CsvRecord) bool { startedTs, err := time.Parse(config.DefaultDateTimePattern, r.StartedTs) if err != nil { log.Fatalln("Error in TodaysRowsCsvRecordPredicate:", err) } return startedTs.Format(config.DefaultDatePattern) == time.Now().Format(config.DefaultDatePattern) }
TodaysRowsCsvRecordPredicate filters rows with startedTs = today
Functions ¶
This section is empty.
Types ¶
type CsvFile ¶
type CsvFile struct { Path string Header CsvHeader Records CsvRecords }
CsvFile represents a CSV file with header and records. Use Read() and Write() to read and write data from/to disk
func NewCsvFile ¶
NewCsvFile creates a new CsvFile with the given path and default header
func (*CsvFile) Read ¶
func (f *CsvFile) Read(recordFilter CsvRecordPredicate)
ReadAll reads CSV file from disk with records which satisfy recordFilter predicate. Records, not matching the predicate will not be added to CsvFile.Records
func (*CsvFile) ReadAll ¶
func (f *CsvFile) ReadAll()
ReadAll reads CSV file from disk with all records
func (*CsvFile) UpdateRecord ¶
UpdateRecord replaces record at the given index with the new record.
type CsvRecord ¶
type CsvRecord struct { ID string StartedTs string Comment string // TimeSpent string `validate:"required"` // Ticket string `validate:"required"` TimeSpent string `validate:"required,timespent"` Ticket string `validate:"required,jiraticket"` Category string // contains filtered or unexported fields }
CsvRecord represents a single record in a CSV file
func NewCsvRecord ¶
NewCsvRecord created a new CsvRecord from a slice representing a single CSV row
type CsvRecordPredicate ¶
CsvRecordPredicate used as a condition for rows filtering when reading CSV file
type CsvRecords ¶
type CsvRecords []CsvRecord
CsvRecords is a wrapper on []CsvRecord
func (*CsvRecords) AsRows ¶
func (recs *CsvRecords) AsRows() [][]string
AsRows converts CsvRecords into 2-d slice representing CSV {records X columns}
func (*CsvRecords) Filter ¶
func (recs *CsvRecords) Filter(recordFilter CsvRecordPredicate) CsvRecords
Filter returns a copy of records, filtered using the given recordFilter