Documentation
¶
Index ¶
- type AskForValueFunc
- type CalculatedField
- type ColumnConfiguration
- type Condition
- type Conditions
- type Configuration
- type ExtraVariable
- type FieldLocation
- type Mapper
- type NewRecordFunc
- type Operand
- type OptionFunc
- func WithArray(array bool) OptionFunc
- func WithLogger(logger *slog.Logger) OptionFunc
- func WithNamed(named bool) OptionFunc
- func WithNestedPropertyName(propertyName string) OptionFunc
- func WithOptions(mapping []byte) OptionFunc
- func WithOutputType(outputType string) OptionFunc
- func WithSeparator(separator string) OptionFunc
- type PropertyConfiguration
- type RecordWithInformation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AskForValueFunc ¶ added in v0.9.0
type AskForValueFunc func(record, header []string, field CalculatedField) (string, error)
AskForValueFunc defines a function type that calculates a string value based on a record, header, and a calculated field.
type CalculatedField ¶
type CalculatedField struct {
// Property specifies the name of the property in the generated document.
Property string `json:"property"`
// Kind denotes what kind of calculate has to be treated
Kind string `json:"kind"`
// Format denotes a formatting value or the value to acquire
Format string `json:"format"`
// Type informa about the type represented
Type string `json:"type"`
// Location specifies the location or context where the calculated field applies in the mapping.
//Either document or record
Location FieldLocation `json:"location"`
}
CalculatedField defines a structure for representing dynamically computed fields within a configuration.
type ColumnConfiguration ¶
type ColumnConfiguration struct {
// Properties represents a list of property configurations defining column mappings in the mapping structure.
Properties []PropertyConfiguration `json:"properties"`
// Property specifies the name of the column property in the mapping configuration.
Property string `json:"property"`
// Type specifies the data type of the column in the mapping configuration.
Type string `json:"type"`
}
ColumnConfiguration defines the structure for configuring a column's property and type in a mapping.
type Condition ¶
type Condition struct {
// Operand1 represents the first operand in a condition, which defines a value and its type for evaluation.
Operand1 Operand `json:"operand1"`
// Operand2 represents the second operand in a condition, defining its type and value for evaluation.
Operand2 Operand `json:"operand2"`
// Operator specifies the condition operator (e.g., '=', '!=', '>', '<') to be applied for comparison in the mapping configuration.
Operator string `json:"operator"`
// Type denotes the data type for the comparison
Type string `json:"type"`
}
Condition defines a structure for representing a condition with a value and an associated operator.
type Conditions ¶ added in v0.9.0
type Conditions []Condition
Conditions defines a slice of conditions to be evaluated for filtering data
func (*Conditions) Apply ¶ added in v0.9.0
func (cs *Conditions) Apply(logger *slog.Logger, property string, recordInfo *RecordWithInformation) bool
Apply checks whether all conditions apply to the specified record and header.
type Configuration ¶
type Configuration struct {
// ExtraVariables is the list of all defines variables
ExtraVariables map[string]ExtraVariable `json:"extra_variables"`
// Calculated represents a slice of calculated fields to be included in the configuration, each defined by CalculatedField.
Calculated []CalculatedField `json:"calculated"`
// Mapping represents a map of keys to their corresponding column configurations in the mapping structure.
Mapping map[string]ColumnConfiguration `json:"mapping"`
// Filter represents a mapping of key-value pairs where each key maps to a slice of conditions for filtering data.
Filter map[string]Conditions `json:"filter"`
}
Configuration represents a mapping configuration where keys map to ColumnConfiguration structures.
type ExtraVariable ¶
type ExtraVariable struct {
// Value contains the string representation of the variable
Value string `json:"value"`
}
ExtraVariable is used to store a static extra variable in the mapping
type FieldLocation ¶ added in v0.9.0
type FieldLocation string
FieldLocation represents the location or identifier of a specific field within a system or context as a string.
const DocumentLocation FieldLocation = "document"
const RecordLocation FieldLocation = "record"
func (*FieldLocation) IsValid ¶ added in v0.9.0
func (fl *FieldLocation) IsValid() bool
IsValid checks if the FieldLocation has a valid value, returning true for RecordLocation or DocumentLocation, false otherwise.
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper defines a structure for mapping input data to output data, applying configuration and marshaling as needed.
func NewMapper ¶
func NewMapper(options ...OptionFunc) (*Mapper, error)
NewMapper creates and initializes a new Mapper instance using the provided OptionFunc configurations.
func (*Mapper) Map ¶
Map processes input CSV data, maps it to JSON according to the configuration, and writes the result to the output destination.
func (*Mapper) SetAskForValueFunc ¶ added in v0.9.0
func (m *Mapper) SetAskForValueFunc(f AskForValueFunc)
SetAskForValueFunc sets the function responsible for dynamically providing string values based on record, header, and field.
func (*Mapper) SetNewRecordFunc ¶ added in v0.9.0
func (m *Mapper) SetNewRecordFunc(n NewRecordFunc)
SetNewRecordFunc sets the function to be called when processing a new record.
type NewRecordFunc ¶ added in v0.9.0
NewRecordFunc represents a function called when a new record is being processed
type OptionFunc ¶
OptionFunc defines a function signature for configuring a Mapper instance with specific options or parameters.
func WithArray ¶
func WithArray(array bool) OptionFunc
WithArray sets the "array" field of the Mapper instance to the provided boolean value.
func WithLogger ¶
func WithLogger(logger *slog.Logger) OptionFunc
WithLogger sets a custom logger for the Mapper instance. Returns an OptionFunc to configure the logger.
func WithNamed ¶
func WithNamed(named bool) OptionFunc
WithNamed sets the "named" field of the Mapper instance to the provided boolean value.
func WithNestedPropertyName ¶
func WithNestedPropertyName(propertyName string) OptionFunc
WithNestedPropertyName sets the property name for TOML array output.
func WithOptions ¶
func WithOptions(mapping []byte) OptionFunc
WithOptions sets the options for the mapper
func WithOutputType ¶
func WithOutputType(outputType string) OptionFunc
WithOutputType sets the specified output type for marshaling data in a Mapper instance.
func WithSeparator ¶
func WithSeparator(separator string) OptionFunc
WithSeparator returns an OptionFunc that sets the character delimiter for CSV records in the Mapper instance.
type PropertyConfiguration ¶
type PropertyConfiguration struct {
// Property specifies the name of the column property in the mapping configuration.
Property string `json:"property"`
// Type specifies the data type of the column in the mapping configuration.
Type string `json:"type"`
// Condition specifies the logical condition to be evaluated for a property, including value, column, and comparison operator.
Condition *Condition `json:"condition,omitempty"`
}
PropertyConfiguration defines the mapping configuration for a single property, including its name and data type.
func (*PropertyConfiguration) Applies ¶
func (pc *PropertyConfiguration) Applies(logger *slog.Logger, recordInfo *RecordWithInformation) bool
Applies returns true if the property configuration applies to the given record.
type RecordWithInformation ¶ added in v0.10.0
type RecordWithInformation struct {
// Record represents a collection of string values, typically used to store multiple related pieces of data.
Record []string
// Header represents a collection of strings typically used for storing key names or metadata information.
Header []string
// HeaderIndex maps header names to their corresponding column indices for quick lookup in a data processing context.
HeaderIndex map[string]int
}
RecordWithInformation represents a structured data record with a header and associated metadata.
func (*RecordWithInformation) GetValue ¶ added in v0.10.0
GetValue retrieves a value from the record based on the specified type and column, converting it to the target type t. Logs errors for invalid headers or indices using the provided logger. Returns the converted value or an error if the operation fails.