Documentation
¶
Index ¶
- type Cell
- type CellLocation
- type ConcatCellLocation
- type Csv
- func (c Csv) MarshalJSON() ([]byte, error)
- func (c *Csv) ParseFile(filePath string) ([]map[string]any, []string, error)
- func (c *Csv) ParseFileNames(filePath string) (map[string]string, error)
- func (c *Csv) ParseRecords(records [][]string) (any, error)
- func (c *Csv) ParseRecordsSegmented(records [][]string) (cells map[string]any, concatCells map[string]any, tables map[string]any, ...)
- func (c *Csv) Process(filepath string) (result [][]byte, id []string, err error)
- func (c *Csv) UnmarshalJSON(data []byte) error
- type DataType
- type FilePathData
- type Float64
- type IdField
- type IdFieldParameter
- type Processor
- type ProcessorFillRight
- type ProcessorMergeColumns
- type ProcessorMergeRows
- type ProcessorRemoveCellLeft
- type ProcessorReplaceCell
- type ProcessorTransposeRow
- type ProcessorType
- type TableLocation
- type TimeField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CellLocation ¶
type CellLocation struct {
Location Cell
DataType DataType
Name string // Alias that will be used if not blank
NameCell Cell // Location for the name cell. Will be ignored if Name is not blank
}
Represents data that is within a single cell (not a table)
The cell may contain an associated cell that is the name of the cell or the name can be supplied directly.
func NewCellLocation ¶
type ConcatCellLocation ¶
type ConcatCellLocation struct {
Cells []Cell // List of cells in order to be concatenated
Delimiter string // Delimiter to use between cells
Name string // Alias that will be used if not blank
NameCell Cell // Location for the name cell. Will be ignored if Name is not blank
DataType DataType
}
Represents cell data that spans multiple consecutive rows or columns
func NewConcatCellLocation ¶
type Csv ¶
type Csv struct {
FilePathData []FilePathData
PreProcessor []Processor
CellLocations []CellLocation
ConcatCellLocations []ConcatCellLocation
TableLocations []TableLocation
TimeFields []TimeField
IdField IdField
FaultOnDuplicate bool
KeepSpaces bool
StoreFileTime bool
FileTimeName string
}
func NewCsvFile ¶
func NewCsvFile(cellLocations []CellLocation, concatCellLocations []ConcatCellLocation, tableLocations []TableLocation) *Csv
func (Csv) MarshalJSON ¶
func (*Csv) ParseFile ¶
Parse a file and return all the results grouped.
Will output either a map[string]any or []map[string]any
func (*Csv) ParseFileNames ¶
func (*Csv) ParseRecordsSegmented ¶
func (c *Csv) ParseRecordsSegmented(records [][]string) (cells map[string]any, concatCells map[string]any, tables map[string]any, timestamps map[string]time.Time, err error)
parse a file and return all results per type of search
func (*Csv) UnmarshalJSON ¶
type DataType ¶
type DataType int
Type mapping
const ( DataTypeAuto DataType = iota // Infers data type from data DataTypeSplit // Creates a column with the type appended to the name. Is treated like auto on everything but tables DataTypeString DataTypeInt64 DataTypeFloat64 DataTypeBool DataTypeDateTimeStyle0 // Assumes local time | YYYY-MM-DD HH:MM:SS DataTypeDateTimeStyle1 // Assumes local time | YYYY/MM/DD HH:MM:SS )
type FilePathData ¶
type Float64 ¶
type Float64 float64 // Custom type to handle mapping with decimals
func (Float64) MarshalJSON ¶
type IdField ¶
type IdField struct {
// a grouping of parameters tht can be any depth into the data
Parameters []IdFieldParameter
Delimiter string
}
type IdFieldParameter ¶
type IdFieldParameter struct {
Mapping []any
}
type Processor ¶
type Processor interface {
GetName() string
Execute(records [][]string) ([][]string, error)
GetType() ProcessorType
SetType()
}
type ProcessorFillRight ¶
type ProcessorFillRight struct {
Type ProcessorType
Name string
Start Cell
End Cell // Set Row = -1 if you want to do all rows, Set Column = -1 if you want to do all columns
}
Fills blank spaces using data to the left of the blank column ¶
Example:
input := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2", "r1c3"},
{"r2c0", "r2c1", , , "r2c2"},
{"r3c0", "r3c1", , , "r3c2"},
{"r4c0", "r4c1", , , "r4c2"},
}
action:= &ProcessorFillRight{
Start: Cell{Row: 2, Column: 0},
End: Cell{Row: 4, Column: 4},
}
output := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2", "r1c3"},
{"r2c0", "r2c1", "r2c1", , "r2c2"},
{"r3c0", "r3c1", "r3c1", , "r3c2"},
{"r4c0", "r4c1", , , "r4c2"},
}
func (*ProcessorFillRight) Execute ¶
func (a *ProcessorFillRight) Execute(records [][]string) ([][]string, error)
func (*ProcessorFillRight) GetName ¶
func (a *ProcessorFillRight) GetName() string
func (*ProcessorFillRight) GetType ¶
func (a *ProcessorFillRight) GetType() ProcessorType
func (*ProcessorFillRight) SetType ¶
func (a *ProcessorFillRight) SetType()
type ProcessorMergeColumns ¶
type ProcessorMergeColumns struct {
Type ProcessorType
Name string
Start Cell
End Cell // Set Row = -1 if you want to do all rows, Set Column = -1 if you want to do all columns
Delimiter string
}
Merge one or more columns together across defined rows ¶
Example:
input := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2", "r1c3"},
{"r2c0", "r2c1", "r2c2"},
{"r3c0", "r3c1", "r3c2"},
{"r4c0", "r4c1", "r4c2"},
}
action:= &ProcessorMergeColumns{
Start: Cell{Row: 2, Column: 0},
End: Cell{Row: 4, Column: 2},
}
output := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2", "r1c3"},
{"r2c0r2c1", "r2c2"},
{"r3c0r3c1", "r3c2"},
{"r4c0", "r4c1", "r4c2"},
}
func (*ProcessorMergeColumns) Execute ¶
func (a *ProcessorMergeColumns) Execute(records [][]string) ([][]string, error)
func (*ProcessorMergeColumns) GetName ¶
func (a *ProcessorMergeColumns) GetName() string
func (*ProcessorMergeColumns) GetType ¶
func (a *ProcessorMergeColumns) GetType() ProcessorType
func (*ProcessorMergeColumns) SetType ¶
func (a *ProcessorMergeColumns) SetType()
type ProcessorMergeRows ¶
type ProcessorMergeRows struct {
Type ProcessorType
Name string
StartRow int
EndRow int
Delimiter string
TrimWhitespace bool
}
Merge one or more rows together. ¶
Note: All rows must be the same length
Example:
input := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2", "r1c3"},
{"r2c0", "r2c1", "r2c2"},
{"r3c0", "r3c1", "r3c2"},
{"r4c0", "r4c1", "r4c2"},
}
action:= &ProcessorMergeRows{
StartRow: 2,
EndRow: 4,
}
output := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2", "r1c3"},
{"r2c0r3c0", "r2c1r3c1", "r2c2r3c2"},
{"r4c0", "r4c1", "r4c2"},
}
func (*ProcessorMergeRows) Execute ¶
func (a *ProcessorMergeRows) Execute(records [][]string) ([][]string, error)
func (*ProcessorMergeRows) GetName ¶
func (a *ProcessorMergeRows) GetName() string
func (*ProcessorMergeRows) GetType ¶
func (a *ProcessorMergeRows) GetType() ProcessorType
func (*ProcessorMergeRows) SetType ¶
func (a *ProcessorMergeRows) SetType()
type ProcessorRemoveCellLeft ¶
type ProcessorRemoveCellLeft struct {
Type ProcessorType
Name string
Cell Cell
}
Removes a cell and shifts left ¶
Example:
input := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2"},
}
action:= &ProcessorFillRight{
Cell: Cell{Row: 0, Column: 0},
}
output := [][]string{
{"r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2"},
}
func (*ProcessorRemoveCellLeft) Execute ¶
func (a *ProcessorRemoveCellLeft) Execute(records [][]string) ([][]string, error)
func (*ProcessorRemoveCellLeft) GetName ¶
func (a *ProcessorRemoveCellLeft) GetName() string
func (*ProcessorRemoveCellLeft) GetType ¶
func (a *ProcessorRemoveCellLeft) GetType() ProcessorType
func (*ProcessorRemoveCellLeft) SetType ¶
func (a *ProcessorRemoveCellLeft) SetType()
type ProcessorReplaceCell ¶
type ProcessorReplaceCell struct {
Type ProcessorType
Name string
Cell Cell
Value string
}
Replaces a cell's value with another ¶
Example:
input := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2"},
}
action:= &ProcessorFillRight{
Cell: Cell{Row: 0, Column: 0},
Value: "header1",
}
output := [][]string{
{"header1", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2"},
}
func (*ProcessorReplaceCell) Execute ¶
func (a *ProcessorReplaceCell) Execute(records [][]string) ([][]string, error)
func (*ProcessorReplaceCell) GetName ¶
func (a *ProcessorReplaceCell) GetName() string
func (*ProcessorReplaceCell) GetType ¶
func (a *ProcessorReplaceCell) GetType() ProcessorType
func (*ProcessorReplaceCell) SetType ¶
func (a *ProcessorReplaceCell) SetType()
type ProcessorTransposeRow ¶
type ProcessorTransposeRow struct {
Type ProcessorType
Name string
StartRow int
EndRow int
}
Transpose data from horizontal to vertical or vice versa ¶
Example:
input := [][]string{
{"r0c0", "r0c1", "r0c2"},
{"r1c0", "r1c1", "r1c2"},
}
action:= &ProcessorTransposeRow{
StartRow: 0,
EndRow: -1
}
output := [][]string{
{"r0c0", "r1c0"},
{"r0c1", "r1c1"},
{"r0c2", "r1c2"},
}
func (*ProcessorTransposeRow) Execute ¶
func (a *ProcessorTransposeRow) Execute(records [][]string) ([][]string, error)
func (*ProcessorTransposeRow) GetName ¶
func (a *ProcessorTransposeRow) GetName() string
func (*ProcessorTransposeRow) GetType ¶
func (a *ProcessorTransposeRow) GetType() ProcessorType
func (*ProcessorTransposeRow) SetType ¶
func (a *ProcessorTransposeRow) SetType()
type ProcessorType ¶
type ProcessorType int
const ( ProcessorTypeMergeColumns ProcessorType = iota ProcessorTypeMergeRows ProcessorTypeFillRight ProcessorTypeReplaceCell ProcessorTypeTransposeRow ProcessorTypeRemoveCellLeft ProcessorTypeEnd // Used to confirm all types are accounted for )
type TableLocation ¶
type TableLocation struct {
Name string // name of the table. will be used instead of NameLocation if both are provided
NameLocation Cell // if not 0, 0 it will be used to identify the name of the table
StartCell Cell
EndCell Cell // if 0, 0 or equal to start cell it will not execute. Negative values will be treated as the end of the row or column
HeaderNames []string // Ignored if TableHasHeader is true
ColumnDataTypes []DataType // Ignored if AutoColumnDataTypes is true.
TableHasHeader bool // Whether the first row is the header row or not
AutoColumnDataTypes bool // if true will automatically infer column data types from the data
SkipBlankData bool // Skips returning data for a cell if the cell is blank
ParseAsArray bool // If true will parse the fields as an array instead of a JSON list
ParseSingleRow bool // If true will only take the first row (or row beneath header) regardless of number of rows
ParseSeparated bool // If true will segment table into multiple maps
IgnoreNesting bool // If true will not nest the fields under the table name
}
Represents data that is within a table.
func NewTableLocation ¶
Click to show internal directories.
Click to hide internal directories.