extract

package
v0.0.0-...-599599a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolType

type BoolType struct{}

BoolType implementation

func (BoolType) Format

func (b BoolType) Format(v any) string

func (BoolType) Name

func (b BoolType) Name() string

func (BoolType) Parse

func (b BoolType) Parse(str string) (any, error)

func (BoolType) Validate

func (b BoolType) Validate(v any) bool

func (BoolType) Zero

func (b BoolType) Zero() any

type DataType

type DataType interface {
	// Name returns the name of the datatype being used
	Name() string

	// Zero returns the zero value of the datatype
	Zero() any

	// Validate, validates that the assigned datatype works for the value
	// that was passed in
	// returns true/false if the value supplied is of the datatype used
	Validate(v any) bool

	// Format returns a formatted string of the value
	// corresponding to the datatype used
	Format(v any) string

	// Parse attempts to convert the string value provided into the
	// datattype assigned.
	// Returns the converted datatype value as a string, int, bool, etc
	// and error message if the string value could not be converted
	Parse(s string) (any, error)
}

main datatype interface declares that any DataType used in mapping of fields must include the following methods

type Field

type Field struct {
	Name      string
	Index     int
	Offset    int
	OffsetLen int
	Type      DataType
	Delimiter string
}

func NewField

func NewField(name string, dataType DataType, options ...Option) (Field, error)

NewField creates a Field with validation

type FieldMap

type FieldMap struct {
	Fields []Field
}

func NewFieldMap

func NewFieldMap(fields ...Field) *FieldMap

Contstructor for new FieldMap returns a FieldMap

func (*FieldMap) AddField

func (fm *FieldMap) AddField(f Field) error

Add more fields

func (*FieldMap) GetFieldByIndex

func (fm *FieldMap) GetFieldByIndex(inIdx int) (Field, bool)

GetFieldByIndex functions like a _,ok idiom similar to GetFieldByName, but returns a field who's index matches the value passed into the function call

func (*FieldMap) GetFieldByName

func (fm *FieldMap) GetFieldByName(inName string) (Field, bool)

GetFieldByName functions like a _,ok idiom if the name passed in matches one of the fields on FieldMap, then it is returned if not, an empty Field is returned with False

func (*FieldMap) GetFields

func (fm *FieldMap) GetFields() []Field

Getter method

type IntType

type IntType struct{}

IntType implementation

func (IntType) Format

func (i IntType) Format(v any) string

func (IntType) Name

func (i IntType) Name() string

func (IntType) Parse

func (i IntType) Parse(str string) (any, error)

func (IntType) Validate

func (i IntType) Validate(v any) bool

func (IntType) Zero

func (i IntType) Zero() any

type Option

type Option func(*Field) error

func WithIndex

func WithIndex(i int) Option

WithIndex specifies the index of the field (first is 0) this is to be used with DELIMITED files where the delimiter is later specified on the extraction engine.

ex: someField = NewField("MyField", StringType{}, WithIndex(0))

func WithOffset

func WithOffset(start int, length int) Option

WithOffset specifies the start char (position 1 = 1) of the field followed by the length of the field. This is to be used with FIXED WIDTH files

ex: someField = NewField("MyField", StringType{}, WithOffset(1, 15))

type RowData

type RowData struct{}

func ParseDelimitted

func ParseDelimitted(fullPath string, delimiter string, fieldMap FieldMap) ([]RowData, error)

ParseDelimitted iterates over a delimitted file for each row it creates a rowData struct (rd) per the field mapping provided

returns a slice of rowData structs in the order of the original file

type StringType

type StringType struct{}

StringType implementation

func (StringType) Format

func (s StringType) Format(v any) string

func (StringType) Name

func (s StringType) Name() string

func (StringType) Parse

func (s StringType) Parse(str string) (any, error)

func (StringType) Validate

func (s StringType) Validate(v any) bool

func (StringType) Zero

func (s StringType) Zero() any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL